mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 22:35:01 +00:00
[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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user