diff --git a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php index e18f660c9..e8b67e0ab 100644 --- a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php +++ b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php @@ -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')); } diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php index e560e3871..448588338 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php @@ -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