Files
chill-bundles/src/Bundle/ChillDocStoreBundle/Service/Lock/CleanOldLockCronJob.php
Julien Fastré c60383b636 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.
2026-04-08 22:26:43 +02:00

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 [];
}
}