Fix: Pass $serverTimezone to shouldRunNow() in ServerCheckJob dispatch
Pass the server timezone parameter to shouldRunNow() call at line 127, ensuring ServerCheckJob dispatch respects the server's local timezone instead of falling back to the instance default. This aligns the behavior with other scheduled tasks in the same method: - ServerStorageCheckJob (line 137) - ServerPatchCheckJob (line 144) - Sentinel restart (line 152) All scheduled tasks in processServerTasks() now consistently use the server's configured timezone for cron evaluation. Added unit test to verify timezone-aware cron schedule evaluation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ed5796739f
commit
8ff83cc3d6
2 changed files with 25 additions and 1 deletions
|
|
@ -124,7 +124,7 @@ private function processServerTasks(Server $server): void
|
|||
|
||||
if ($sentinelOutOfSync) {
|
||||
// Dispatch ServerCheckJob if Sentinel is out of sync
|
||||
if ($this->shouldRunNow($this->checkFrequency)) {
|
||||
if ($this->shouldRunNow($this->checkFrequency, $serverTimezone)) {
|
||||
ServerCheckJob::dispatch($server);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,3 +95,27 @@
|
|||
// The executionTime is now 1680 seconds (28 minutes) earlier than it should be!
|
||||
expect($executionTime->diffInSeconds(Carbon::parse('2024-12-02 12:00:00')))->toEqual(1680);
|
||||
});
|
||||
|
||||
it('respects server timezone when evaluating cron schedules', function () {
|
||||
// This test verifies that timezone parameter affects cron evaluation
|
||||
// Set a fixed test time at 23:00 UTC
|
||||
Carbon::setTestNow('2024-12-02 23:00:00', 'UTC');
|
||||
|
||||
$executionTime = Carbon::now();
|
||||
$cronExpression = new \Cron\CronExpression('0 23 * * *'); // Every day at 11 PM
|
||||
|
||||
// Test 1: UTC timezone at 23:00 - should match
|
||||
$timeInUTC = $executionTime->copy()->setTimezone('UTC');
|
||||
expect($cronExpression->isDue($timeInUTC))->toBeTrue();
|
||||
|
||||
// Test 2: America/New_York timezone - 23:00 UTC is 18:00 EST, should not match 23:00 cron
|
||||
$timeInEST = $executionTime->copy()->setTimezone('America/New_York');
|
||||
expect($cronExpression->isDue($timeInEST))->toBeFalse();
|
||||
|
||||
// Test 3: Asia/Tokyo timezone - 23:00 UTC is 08:00 JST next day, should not match 23:00 cron
|
||||
$timeInJST = $executionTime->copy()->setTimezone('Asia/Tokyo');
|
||||
expect($cronExpression->isDue($timeInJST))->toBeFalse();
|
||||
|
||||
// Test 4: Verify copy() preserves the original time
|
||||
expect($executionTime->toDateTimeString())->toBe('2024-12-02 23:00:00');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue