connection = $connection; } public function canRun(?CronJobExecution $cronJobExecution): bool { if (null === $cronJobExecution) { return true; } if ($cronJobExecution->getKey() !== $this->getKey()) { throw new UnexpectedValueException(); } $now = new DateTimeImmutable('now'); return $cronJobExecution->getLastStart() < $now->sub(new DateInterval('P1D')) // introduce a random component to ensure a roll when multiple instances are hosted on same machines && random_int(0, 10) === 0; } public function getKey(): string { return 'refresh-materialized-view-address-to-geog-units'; } public function run(): void { $this->connection->executeQuery('REFRESH MATERIALIZED VIEW view_chill_main_address_geographical_unit'); } }