[cron-job] allow a cronjob to pass data from one execution to another

When a cronjob is executed, it may return an array of data.

This data will be passed as parameter on the next execution
This commit is contained in:
2023-07-12 11:36:26 +02:00
parent e38b369149
commit 3f66e1a862
7 changed files with 137 additions and 11 deletions

View File

@@ -40,7 +40,7 @@ final class CronManagerTest extends TestCase
$jobToExecute = $this->prophesize(CronJobInterface::class);
$jobToExecute->getKey()->willReturn('to-exec');
$jobToExecute->canRun(Argument::type(CronJobExecution::class))->willReturn(true);
$jobToExecute->run()->shouldBeCalled();
$jobToExecute->run([])->shouldBeCalled();
$executions = [
['key' => $jobOld1->getKey(), 'lastStart' => new DateTimeImmutable('yesterday'), 'lastEnd' => new DateTimeImmutable('1 hours ago'), 'lastStatus' => CronJobExecution::SUCCESS],
@@ -64,7 +64,7 @@ final class CronManagerTest extends TestCase
$jobAlreadyExecuted = new JobCanRun('k');
$jobNeverExecuted = $this->prophesize(CronJobInterface::class);
$jobNeverExecuted->getKey()->willReturn('never-executed');
$jobNeverExecuted->run()->shouldBeCalled();
$jobNeverExecuted->run([])->shouldBeCalled();
$jobNeverExecuted->canRun(null)->willReturn(true);
$executions = [
@@ -86,7 +86,7 @@ final class CronManagerTest extends TestCase
$jobAlreadyExecuted = new JobCanRun('k');
$jobNeverExecuted = $this->prophesize(CronJobInterface::class);
$jobNeverExecuted->getKey()->willReturn('never-executed');
$jobNeverExecuted->run()->shouldBeCalled();
$jobNeverExecuted->run([])->shouldBeCalled();
$jobNeverExecuted->canRun(null)->willReturn(true);
$executions = [
@@ -178,8 +178,9 @@ class JobCanRun implements CronJobInterface
return $this->key;
}
public function run(): void
public function run(array $lastExecutionData): null|array
{
return null;
}
}
@@ -195,7 +196,8 @@ class JobCannotRun implements CronJobInterface
return 'job-b';
}
public function run(): void
public function run(array $lastExecutionData): null|array
{
return null;
}
}