Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Feat: cron jobs are executed based on the server timezone

ayntk-ai1892ce4e123c
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index e8f213b161..f1b9bf3d46 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -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');
}
-}
+}
\ No newline at end of file
diff --git a/app/Jobs/ScheduledTaskJob.php b/app/Jobs/ScheduledTaskJob.php
index 819e28f89f..2e8bf40159 100644
--- a/app/Jobs/ScheduledTaskJob.php
+++ b/app/Jobs/ScheduledTaskJob.php
@@ -36,6 +36,8 @@ class ScheduledTaskJob implements ShouldQueue
public array $containers = [];
+ public string $server_timezone;
+
public function __construct($task)
{
$this->task = $task;
@@ -47,6 +49,7 @@ class ScheduledTaskJob implements ShouldQueue
throw new \RuntimeException('ScheduledTaskJob failed: No resource found.');
}
$this->team = Team::find($task->team_id);
+ $this->server_timezone = $this->resource->destination->server->settings->server_timezone;
}
public function middleware(): array
@@ -61,6 +64,7 @@ class ScheduledTaskJob implements ShouldQueue
public function handle(): void
{
+
try {
$this->task_log = ScheduledTaskExecution::create([
'scheduled_task_id' => $this->task->id,
@@ -121,6 +125,8 @@ class ScheduledTaskJob implements ShouldQueue
$this->team?->notify(new TaskFailed($this->task, $e->getMessage()));
// send_internal_notification('ScheduledTaskJob failed with: ' . $e->getMessage());
throw $e;
+ } finally {
+
}
}
-}
+}
\ No newline at end of file