queue optimization

This commit is contained in:
Yuri Kuznetsov
2021-05-24 12:20:40 +03:00
parent da2e2dbf20
commit f774b4bbcf
+11 -2
View File
@@ -165,13 +165,22 @@ class Job
public function hasScheduledJobOnMinute(string $scheduledJobId, string $time) : bool
{
$dateObj = new DateTime($time);
$timeWithoutSeconds = $dateObj->format('Y-m-d H:i:');
$fromString = $dateObj->format('Y-m-d H:i:00');
$toString = $dateObj->format('Y-m-d H:i:59');
$job = $this->getEntityManager()->getRepository('Job')
->select(['id'])
->where([
'scheduledJobId' => $scheduledJobId,
'executeTime*' => $timeWithoutSeconds . '%',
'status' => [ // This forces usage of an appropriate index.
CronManager::PENDING,
CronManager::READY,
CronManager::RUNNING,
CronManager::SUCCESS,
],
'executeTime>=' => $fromString,
'executeTime<=' => $toString,
])
->findOne();