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.

fix(schedule): prevent duplicate SSL certificate regeneration

Andras Bacsaib124397613f5
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 75ec31ae02..3ec59adb3e 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -78,7 +78,7 @@ class Kernel extends ConsoleKernel
// Scheduled Jobs (Backups & Tasks)
$this->scheduleInstance->job(new ScheduledJobManager)->everyMinute()->onOneServer();
- $this->scheduleInstance->job(new RegenerateSslCertJob)->twiceDaily();
+ $this->scheduleInstance->job(new RegenerateSslCertJob)->twiceDaily()->onOneServer();
$this->scheduleInstance->job(new CheckTraefikVersionJob)->weekly()->sundays()->at('00:00')->timezone($this->instanceTimezone)->onOneServer();
diff --git a/tests/Feature/ScheduleOnOneServerTest.php b/tests/Feature/ScheduleOnOneServerTest.php
new file mode 100644
index 0000000000..10758738cc
--- /dev/null
+++ b/tests/Feature/ScheduleOnOneServerTest.php
@@ -0,0 +1,38 @@
+<?php
+
+use App\Models\InstanceSettings;
+use Illuminate\Console\Scheduling\Schedule;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+
+uses(RefreshDatabase::class);
+
+beforeEach(function () {
+ InstanceSettings::unguarded(fn () => InstanceSettings::query()->firstOrCreate(['id' => 0]));
+});
+
+it('schedules RegenerateSslCertJob with onOneServer to prevent multi-server double dispatch', function () {
+ $schedule = app(Schedule::class);
+
+ $event = collect($schedule->events())->first(
+ fn ($e) => str_contains((string) $e->description, 'RegenerateSslCertJob')
+ );
+
+ expect($event)->not->toBeNull();
+ expect($event->onOneServer)->toBeTrue();
+});
+
+it('schedules every production job with onOneServer', function () {
+ $schedule = app(Schedule::class);
+
+ $jobEvents = collect($schedule->events())->filter(
+ fn ($e) => str_contains((string) $e->description, 'App\\Jobs\\')
+ );
+
+ expect($jobEvents)->not->toBeEmpty();
+
+ $jobEvents->each(function ($event) {
+ expect($event->onOneServer)->toBeTrue(
+ "Scheduled job [{$event->description}] is missing ->onOneServer()"
+ );
+ });
+});