Fixed: ensure to execute Refresh Address To Geographical Unit Cronjob even during the day

This commit is contained in:
2022-12-23 13:36:23 +01:00
parent f12f640cb4
commit c8127a1d9d
2 changed files with 29 additions and 5 deletions

View File

@@ -17,12 +17,9 @@ use DateInterval;
use DateTimeImmutable;
use Doctrine\DBAL\Connection;
use UnexpectedValueException;
use function in_array;
class RefreshAddressToGeographicalUnitMaterializedViewCronJob implements CronJobInterface
{
private const ACCEPTED_HOURS = ['0', '1', '2', '3', '4', '5'];
private Connection $connection;
public function __construct(Connection $connection)
@@ -43,9 +40,8 @@ class RefreshAddressToGeographicalUnitMaterializedViewCronJob implements CronJob
$now = new DateTimeImmutable('now');
return $cronJobExecution->getLastStart() < $now->sub(new DateInterval('P1D'))
&& in_array($now->format('H'), self::ACCEPTED_HOURS, true)
// introduce a random component to ensure a roll when multiple instances are hosted on same machines
&& mt_rand(0, 5) === 0;
&& mt_rand(0, 10) === 0;
}
public function getKey(): string