mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-04 10:42:23 +00:00
The missed daily backups on Coolify Cloud came from Redis evicting queue keys (allkeys-lfu on a full instance), not from the scan of all schedules. The next_run_at design (452259aac,5c5740533) did not prevent that, and it added stored state that must be kept in sync on every frequency, timezone, and server change. It was not released, so remove it: - revert next_run_at, its model hooks, the "Next run" UI, and the diagnostics changes; restore scheduled_job_states and the queue overlap lock - a new migration removes the next_run_at columns and creates scheduled_job_states again where the removed migration already ran Keep the changes that fix real problems: - run the manager every minute from the scheduler with `scheduled:dispatch`, so a busy queue cannot delay it past the catch-up window - load the server chain of scheduled backups with each chunk, which removes about 7,000 queries per run on Coolify Cloud - catch Throwable for each schedule, so one broken schedule does not stop the others - publish database and volume backups again when their queued job was not started after 60 minutes (for example, lost in Redis); log lost tasks and Docker cleanups as missed. A lost backup is not run again when a newer occurrence of the same schedule exists.
64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
|
|
use App\Jobs\ScheduledJobManager;
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class);
|
|
|
|
it('uses WithoutOverlapping middleware with expireAfter to prevent stale locks', function () {
|
|
$job = new ScheduledJobManager;
|
|
$middleware = $job->middleware();
|
|
|
|
// Assert middleware exists
|
|
expect($middleware)->toBeArray()
|
|
->and($middleware)->toHaveCount(1);
|
|
|
|
$overlappingMiddleware = $middleware[0];
|
|
|
|
// Assert it's a WithoutOverlapping instance
|
|
expect($overlappingMiddleware)->toBeInstanceOf(WithoutOverlapping::class);
|
|
|
|
// Use reflection to check private properties
|
|
$reflection = new ReflectionClass($overlappingMiddleware);
|
|
|
|
// Check expireAfter is set (should be 60 seconds - matches job frequency)
|
|
$expiresAfterProperty = $reflection->getProperty('expiresAfter');
|
|
$expiresAfterProperty->setAccessible(true);
|
|
$expiresAfter = $expiresAfterProperty->getValue($overlappingMiddleware);
|
|
|
|
expect($expiresAfter)->toBe(90)
|
|
->and($expiresAfter)->toBeGreaterThan(0, 'expireAfter must be set to prevent stale locks');
|
|
|
|
// Check releaseAfter is NOT set (we use dontRelease)
|
|
$releaseAfterProperty = $reflection->getProperty('releaseAfter');
|
|
$releaseAfterProperty->setAccessible(true);
|
|
$releaseAfter = $releaseAfterProperty->getValue($overlappingMiddleware);
|
|
|
|
expect($releaseAfter)->toBeNull('releaseAfter should be null when using dontRelease()');
|
|
|
|
// Check the lock key
|
|
$keyProperty = $reflection->getProperty('key');
|
|
$keyProperty->setAccessible(true);
|
|
$key = $keyProperty->getValue($overlappingMiddleware);
|
|
|
|
expect($key)->toBe('scheduled-job-manager');
|
|
});
|
|
|
|
it('prevents stale locks by ensuring expireAfter is always set', function () {
|
|
$job = new ScheduledJobManager;
|
|
$middleware = $job->middleware();
|
|
|
|
$overlappingMiddleware = $middleware[0];
|
|
$reflection = new ReflectionClass($overlappingMiddleware);
|
|
|
|
$expiresAfterProperty = $reflection->getProperty('expiresAfter');
|
|
$expiresAfterProperty->setAccessible(true);
|
|
$expiresAfter = $expiresAfterProperty->getValue($overlappingMiddleware);
|
|
|
|
// Critical check: expireAfter MUST be set to prevent GitHub issue #4539
|
|
expect($expiresAfter)->not->toBeNull(
|
|
'expireAfter() is required to prevent stale locks (see GitHub #4539)'
|
|
);
|
|
});
|