diff --git a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflow.php b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflow.php index 078402855..118b9f57e 100644 --- a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflow.php +++ b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflow.php @@ -1,12 +1,19 @@ clock->now() >= $cronJobExecution->getLastEnd()->add(new DateInterval('P1D')); + return $this->clock->now() >= $cronJobExecution->getLastEnd()->add(new \DateInterval('P1D')); } public function getKey(): string @@ -40,7 +47,7 @@ class CancelStaleWorkflowCronJob implements CronJobInterface { $this->logger->info('Cronjob started: Canceling stale workflows.'); - $olderThanDate = $this->clock->now()->sub(new DateInterval(self::KEEP_INTERVAL)); + $olderThanDate = $this->clock->now()->sub(new \DateInterval(self::KEEP_INTERVAL)); $staleWorkflowIds = $this->workflowRepository->findWorkflowsWithoutFinalStepAndOlderThan($olderThanDate); $lastCanceled = self::LAST_CANCELED_WORKFLOW; $processedCount = 0; @@ -49,10 +56,10 @@ class CancelStaleWorkflowCronJob implements CronJobInterface try { $this->messageBus->dispatch(new CancelStaleWorkflow($wId)); $lastCanceled = $wId; - $processedCount++; + ++$processedCount; } catch (\Exception $e) { - $this->logger->error("Failed to dispatch CancelStaleWorkflow for ID {$wId}", ['exception' => $e]); - continue; + $this->logger->error("Failed to dispatch CancelStaleWorkflow for ID {$wId}", ['exception' => $e]); + continue; } } diff --git a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php index e35464f1d..533283a59 100644 --- a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php +++ b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php @@ -1,5 +1,14 @@ em->remove($workflow->getCurrentStep()); $this->em->remove($workflow); } else { @@ -46,12 +53,8 @@ class CancelStaleWorkflowHandler if (!$transitionApplied) { $this->logger->error(sprintf('No valid transition found for EntityWorkflow %d.', $workflowId)); - throw new UnrecoverableMessageHandlingException( - sprintf('No valid transition found for EntityWorkflow %d.', $workflowId) - ); + throw new UnrecoverableMessageHandlingException(sprintf('No valid transition found for EntityWorkflow %d.', $workflowId)); } } - } - } diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php index 6b654f4df..b56faf79b 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php @@ -23,6 +23,11 @@ use Symfony\Component\Clock\MockClock; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; +/** + * @internal + * + * @coversNothing + */ class CancelStaleWorkflowCronJobTest extends KernelTestCase { protected function setUp(): void @@ -33,6 +38,7 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase /** * @dataProvider buildTestCanRunData + * * @throws \Exception */ public function testCanRun(?CronJobExecution $cronJobExecution, bool $expected): void diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowHandlerTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowHandlerTest.php index 8e2a5ec95..f7887a6cd 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowHandlerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowHandlerTest.php @@ -1,5 +1,14 @@