Skip to content

Commit

Permalink
[CronJob] fix executed when forced
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Apr 22, 2024
1 parent f152fa5 commit 214b44c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/cron-job/Entity/CronJobExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 12 additions & 2 deletions packages/cron-job/Tests/Entity/CronJobExecutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -29,7 +30,7 @@ public function testIsExecutable(
->setActive($active)
->setTimeToLive($timeToLive),
$requestedAt,
false
$forced
);

static::assertSame($expectedExecutable, $execution->isExecutable(Carbon::now()->toDateTimeImmutable()));
Expand All @@ -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,
Expand Down

0 comments on commit 214b44c

Please sign in to comment.