mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-16 10:59:31 +00:00
- 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.
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?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 [];
|
|
}
|
|
}
|