Feat: cron jobs are executed based on the server timezone

This commit is contained in:
ayntk-ai
2024-08-16 12:58:19 +02:00
parent a478ebef2e
commit 1892ce4e12
2 changed files with 13 additions and 5 deletions

View File

@@ -139,10 +139,9 @@ class Kernel extends ConsoleKernel
$service = $scheduled_task->service;
$application = $scheduled_task->application;
if (! $application && ! $service) {
if (!$application && !$service) {
ray('application/service attached to scheduled task does not exist');
$scheduled_task->delete();
continue;
}
if ($application) {
@@ -158,9 +157,12 @@ class Kernel extends ConsoleKernel
if (isset(VALID_CRON_STRINGS[$scheduled_task->frequency])) {
$scheduled_task->frequency = VALID_CRON_STRINGS[$scheduled_task->frequency];
}
$server_timezone = $application ? $application->destination->server->settings->server_timezone : $service->destination->server->settings->server_timezone;
$server_timezone = $server_timezone;
ray($server_timezone);
$schedule->job(new ScheduledTaskJob(
task: $scheduled_task
))->cron($scheduled_task->frequency)->onOneServer();
))->cron($scheduled_task->frequency)->timezone($server_timezone)->onOneServer();
}
}
@@ -170,4 +172,4 @@ class Kernel extends ConsoleKernel
require base_path('routes/console.php');
}
}
}