Fixed cronjobs

This commit is contained in:
2026-05-14 16:58:41 +02:00
parent 30cc0b79c5
commit 454d83de2e
4 changed files with 34 additions and 18 deletions
+5 -2
View File
@@ -41,10 +41,13 @@ class CronTaskHandleProvider extends CommonController
// --- Daily Tasks --- // --- Daily Tasks ---
if ($task->execution_type === CronTaskType::CRON_TASK_TYPE_DAILY) { if ($task->execution_type === CronTaskType::CRON_TASK_TYPE_DAILY) {
$scheduledTime = $task->schedule_time; $scheduledTime = \DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d ') . $task->schedule_time);
$now = Carbon::now();
$alreadyRunToday = $task->last_run?->isToday() ?? false; $alreadyRunToday = $task->last_run?->isToday() ?? false;
if (!$alreadyRunToday && $now->format('H:i') === $scheduledTime) { if (!$alreadyRunToday && $now >= $scheduledTime) {
$this->runTask($task); $this->runTask($task);
} }
} }
+14 -3
View File
@@ -2,6 +2,8 @@
namespace App\Tasks; namespace App\Tasks;
use App\Domains\CostUnit\Actions\ChangeCostUnitState\ChangeCostUnitStateCommand;
use App\Domains\CostUnit\Actions\ChangeCostUnitState\ChangeCostUnitStateRequest;
use App\Models\CostUnit; use App\Models\CostUnit;
use App\Repositories\CostUnitRepository; use App\Repositories\CostUnitRepository;
@@ -12,9 +14,18 @@ class CloseCostUnit implements CronTask {
$costUnitRepository = new CostUnitRepository(); $costUnitRepository = new CostUnitRepository();
/** @var CostUnit $costUnit */ /** @var CostUnit $costUnit */
foreach ($costUnitRepository->getCurrentEvents() as $costUnit) { foreach ($costUnitRepository->getCurrentEvents() as $costUnit) {
if (\DateTime::createFromFormat('Y-m-d', $costUnit->billing_deadline) < $now ) { $billingEndTime = \DateTime::createFromFormat('Y-m-d H:i:s', $costUnit['billing_deadline']);
$costUnit->allow_new = false; $billingEndTime->setTime(0,0,0);
$costUnit->save(); $billingEndTime->add(new \DateInterval('P1D'));
$now = now();
if ($billingEndTime < $now) {
new ChangeCostUnitStateCommand(
new ChangeCostUnitStateRequest(
CostUnit::where('id', $costUnit['id'])->first(),false, false
)
)->execute();
} }
} }
} }
+1 -1
View File
@@ -12,7 +12,7 @@ class CloseEvent implements CronTask {
$eventRepository = new EventRepository(); $eventRepository = new EventRepository();
/** @var Event $event */ /** @var Event $event */
foreach ($eventRepository->getAvailable(false) as $event) { foreach ($eventRepository->getAvailable(false) as $event) {
if ($event->registration_final_end < $now ) { if ($event->registration_final_end <= $now ) {
$event->registration_allowed = false; $event->registration_allowed = false;
$event->save(); $event->save();
} }
+5 -3
View File
@@ -16,16 +16,17 @@ use Psr\Log\LoggerInterface;
class NotifyTeam implements CronTask { class NotifyTeam implements CronTask {
public function handle(): void public function handle(): void
{ {
if (date('w') !== 0) { if ((int)date('w') !== 0) {
// return; return;
} }
$eventRepository = new EventRepository(); $eventRepository = new EventRepository();
/** @var Event $event */ /** @var Event $event */
foreach ($eventRepository->getAvailable(false) as $event) { foreach ($eventRepository->getAvailable(false) as $event) {
foreach (Tenant::all() as $tenant) { foreach (Tenant::all() as $tenant) {
echo $tenant->slug . PHP_EOL;
$participants = $event->participants()->where('local_group', $tenant->slug)->whereNull('unregistered_at')->get(); $participants = $event->participants()->where('local_group', $tenant->slug)->whereNull('unregistered_at')->get();
}
if ($participants->isEmpty()) { if ($participants->isEmpty()) {
continue; continue;
@@ -39,3 +40,4 @@ class NotifyTeam implements CronTask {
} }
} }
} }
}