mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-16 19:09:31 +00:00
Add CleanOldLockCronJob service and corresponding test suite
- Introduced `CleanOldLockCronJob` to handle scheduled cleaning of old locks. - Implemented tests in `CleanOldLockCronJobTest` to verify behavior, including conditions for execution based on elapsed time. - Utilized `MockClock` for precise time-based testing scenarios.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Service\Lock;
|
||||
|
||||
use Chill\MainBundle\Cron\CronJobInterface;
|
||||
use Chill\MainBundle\Entity\CronJobExecution;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
|
||||
final readonly class CleanOldLockCronJob implements CronJobInterface
|
||||
{
|
||||
private const KEY = 'clean-old-stored-object-lock';
|
||||
|
||||
public function __construct(private CleanOldLock $cleanOldLock, private ClockInterface $clock) {}
|
||||
|
||||
public function canRun(?CronJobExecution $cronJobExecution): bool
|
||||
{
|
||||
if (null === $cronJobExecution) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->clock->now() > $cronJobExecution->getLastStart()->add(new \DateInterval('PT12H'));
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
{
|
||||
return self::KEY;
|
||||
}
|
||||
|
||||
public function run(array $lastExecutionData): ?array
|
||||
{
|
||||
($this->cleanOldLock)();
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user