diff --git a/packages/cron-job/Entity/CronJobExecution.php b/packages/cron-job/Entity/CronJobExecution.php index 586e2619..f07c85a4 100644 --- a/packages/cron-job/Entity/CronJobExecution.php +++ b/packages/cron-job/Entity/CronJobExecution.php @@ -146,7 +146,9 @@ public function getCronJob(): ?CronJob public function isExecutable(\DateTimeImmutable $dateTime): bool { - if (!($cronJob = $this->getCronJob())?->isActive()) { + $cronJob = $this->getCronJob(); + + if (!$this->isForce() && !$cronJob?->isActive()) { return false; } diff --git a/packages/cron-job/Tests/Entity/CronJobExecutionTest.php b/packages/cron-job/Tests/Entity/CronJobExecutionTest.php index a3169b96..f3b65bcd 100644 --- a/packages/cron-job/Tests/Entity/CronJobExecutionTest.php +++ b/packages/cron-job/Tests/Entity/CronJobExecutionTest.php @@ -20,7 +20,8 @@ public function testIsExecutable( bool $active, int $timeToLive = 0, ?\DateTimeImmutable $requestedAt = null, - \DateTimeImmutable $now = new \DateTimeImmutable() + \DateTimeImmutable $now = new \DateTimeImmutable(), + bool $forced = false ): void { Carbon::setTestNow($now); @@ -29,7 +30,7 @@ public function testIsExecutable( ->setActive($active) ->setTimeToLive($timeToLive), $requestedAt, - false + $forced ); static::assertSame($expectedExecutable, $execution->isExecutable(Carbon::now()->toDateTimeImmutable())); @@ -44,6 +45,15 @@ public static function provideDataForTestIsExecutable(): iterable '$requestedAt' => new \DateTimeImmutable('2024-04-17 00:00:00'), ]; + yield 'inactive-forced' => [ + '$expectedExecutable' => true, + '$active' => false, + '$timeToLive' => 0, + '$requestedAt' => new \DateTimeImmutable('2024-04-17 00:00:00'), + '$now' => new \DateTimeImmutable('2024-04-17 01:00:00'), + '$forced' => true, + ]; + yield 'active with no time to live' => [ '$expectedExecutable' => true, '$active' => true,