mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
Fixed: [cron] store the last store of executed tasks correctly
This commit is contained in:
parent
5aa59aa0ff
commit
bbd2599e7e
@ -44,7 +44,7 @@ class CronManager implements CronManagerInterface
|
|||||||
|
|
||||||
private const UPDATE_AFTER_EXEC = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastEnd = :now, cr.lastStatus = :status WHERE cr.key = :key';
|
private const UPDATE_AFTER_EXEC = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastEnd = :now, cr.lastStatus = :status WHERE cr.key = :key';
|
||||||
|
|
||||||
private const UPDATE_BEFORE_EXEC = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastExecution = :now WHERE cr.key = :key';
|
private const UPDATE_BEFORE_EXEC = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastStart = :now WHERE cr.key = :key';
|
||||||
|
|
||||||
private CronJobExecutionRepositoryInterface $cronJobExecutionRepository;
|
private CronJobExecutionRepositoryInterface $cronJobExecutionRepository;
|
||||||
|
|
||||||
@ -90,7 +90,8 @@ class CronManager implements CronManagerInterface
|
|||||||
->setParameters([
|
->setParameters([
|
||||||
'now' => new DateTimeImmutable('now'),
|
'now' => new DateTimeImmutable('now'),
|
||||||
'key' => $job->getKey(),
|
'key' => $job->getKey(),
|
||||||
]);
|
])
|
||||||
|
->execute();
|
||||||
} else {
|
} else {
|
||||||
$execution = new CronJobExecution($job->getKey());
|
$execution = new CronJobExecution($job->getKey());
|
||||||
$this->entityManager->persist($execution);
|
$this->entityManager->persist($execution);
|
||||||
|
@ -44,7 +44,7 @@ final class RefreshAddressToGeographicalUnitMaterializedViewCronJobTest extends
|
|||||||
$executedForFirstTime = 0;
|
$executedForFirstTime = 0;
|
||||||
$executedAfterPreviousExecution = 0;
|
$executedAfterPreviousExecution = 0;
|
||||||
|
|
||||||
for ($round = 0; 20 > $round; ++$round ) {
|
for ($round = 0; 20 > $round; ++$round) {
|
||||||
if ($job->canRun(null)) {
|
if ($job->canRun(null)) {
|
||||||
++$executedForFirstTime;
|
++$executedForFirstTime;
|
||||||
}
|
}
|
||||||
@ -58,6 +58,28 @@ final class RefreshAddressToGeographicalUnitMaterializedViewCronJobTest extends
|
|||||||
$this->assertGreaterThan(0, $executedAfterPreviousExecution);
|
$this->assertGreaterThan(0, $executedAfterPreviousExecution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanRunShouldReturnFalse(): void
|
||||||
|
{
|
||||||
|
// As the can run is executed one of ten, this should be executed at least one after
|
||||||
|
// 10 + 5 executions
|
||||||
|
$job = new \Chill\MainBundle\Service\AddressGeographicalUnit\RefreshAddressToGeographicalUnitMaterializedViewCronJob(
|
||||||
|
$this->connection
|
||||||
|
);
|
||||||
|
|
||||||
|
$lastExecution = new CronJobExecution($job->getKey());
|
||||||
|
$lastExecution->setLastStart(new DateTimeImmutable('2 hours ago'));
|
||||||
|
|
||||||
|
$executedAfterPreviousExecution = 0;
|
||||||
|
|
||||||
|
for ($round = 0; 20 > $round; ++$round) {
|
||||||
|
if ($job->canRun($lastExecution)) {
|
||||||
|
++$executedAfterPreviousExecution;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(0, $executedAfterPreviousExecution);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFullRun(): void
|
public function testFullRun(): void
|
||||||
{
|
{
|
||||||
$job = new \Chill\MainBundle\Service\AddressGeographicalUnit\RefreshAddressToGeographicalUnitMaterializedViewCronJob(
|
$job = new \Chill\MainBundle\Service\AddressGeographicalUnit\RefreshAddressToGeographicalUnitMaterializedViewCronJob(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user