Add null check to canRun method in CancelStaleWorkflowCronJob

Ensure the canRun method in CancelStaleWorkflowCronJob returns true when the cron job execution is null. This change includes updating the corresponding test case to cover the new behavior.
This commit is contained in:
Julien Fastré 2024-11-04 14:16:52 +01:00
parent 4dc2348893
commit 5c0a383909
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 9 additions and 0 deletions

View File

@ -37,6 +37,10 @@ class CancelStaleWorkflowCronJob implements CronJobInterface
public function canRun(?CronJobExecution $cronJobExecution): bool
{
if (null === $cronJobExecution) {
return true;
}
return $this->clock->now() >= $cronJobExecution->getLastEnd()->add(new \DateInterval('P1D'));
}

View File

@ -104,6 +104,11 @@ class CancelStaleWorkflowCronJobTest extends TestCase
(new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new \DateTimeImmutable('2023-12-31 00:00:01', new \DateTimeZone('+00:00'))),
false,
];
yield [
null,
true
];
}
private function buildMessageBus(bool $expectDispatchAtLeastOnce = false): MessageBusInterface