Files
coolify/tests/Feature/ScheduledInstanceJobsUniqueLockTest.php
T
Andras Bacsai 6a527051ce fix(jobs): let the unique locks of scheduled instance jobs expire
CleanupInstanceStuffsJob, CleanupOrphanedPreviewContainersJob, and
CheckMissingDatabaseBackupsJob had no uniqueFor. A lock left by a
stopped worker blocked them for up to 24 hours.

- Set uniqueFor to 60, 600, and 1800 seconds
- Give CheckMissingDatabaseBackupsJob a 1800 second timeout, so a run
  cannot outlive its lock
2026-10-05 21:19:23 +02:00

34 lines
1.1 KiB
PHP

<?php
use App\Jobs\CheckMissingDatabaseBackupsJob;
use App\Jobs\CleanupInstanceStuffsJob;
use App\Jobs\CleanupOrphanedPreviewContainersJob;
use Illuminate\Support\Facades\Queue;
beforeEach(function () {
config()->set('cache.default', 'array');
Queue::fake();
});
dataset('scheduled instance jobs', [
'orphaned preview containers cleanup' => [CleanupOrphanedPreviewContainersJob::class, 600],
'instance cleanup' => [CleanupInstanceStuffsJob::class, 60],
'missing database backups check' => [CheckMissingDatabaseBackupsJob::class, 1800],
]);
it('does not queue the job again while its unique lock is held', function (string $jobClass, int $lockSeconds) {
$jobClass::dispatch();
$this->travel($lockSeconds - 1)->seconds();
$jobClass::dispatch();
Queue::assertPushed($jobClass, 1);
})->with('scheduled instance jobs');
it('queues the job again after a unique lock left by a killed worker expires', function (string $jobClass, int $lockSeconds) {
$jobClass::dispatch();
$this->travel($lockSeconds + 1)->seconds();
$jobClass::dispatch();
Queue::assertPushed($jobClass, 2);
})->with('scheduled instance jobs');