scheduleUtil->getActiveScheduledJobList(); $runningScheduledJobIdList = $this->queueUtil->getRunningScheduledJobIdList(); foreach ($activeScheduledJobList as $scheduledJob) { try { $isRunning = in_array($scheduledJob->getId(), $runningScheduledJobIdList); $this->createJobsFromScheduledJob($scheduledJob, $isRunning); } catch (Throwable $e) { $id = $scheduledJob->getId(); $this->log->error("Scheduled Job '{$id}': " . $e->getMessage()); } } } private function createJobsFromScheduledJob(ScheduledJobEntity $scheduledJob, bool $isRunning): void { $id = $scheduledJob->getId(); $executeTime = $this->findExecuteTime($scheduledJob); if ($executeTime === null) { return; } $asSoonAsPossible = $this->checkAsSoonAsPossible($scheduledJob); if (!$asSoonAsPossible) { if ($this->queueUtil->hasScheduledJobOnMinute($id, $executeTime)) { return; } } $jobName = $scheduledJob->getJob(); if ($jobName && $this->metadataProvider->isJobPreparable($jobName)) { $preparator = $this->preparatorFactory->create($jobName); $data = new PreparatorData($scheduledJob->getId(), $scheduledJob->getName() ?? $jobName); /** @var DateTimeImmutable $executeTimeObj */ $executeTimeObj = DateTimeImmutable ::createFromFormat(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT, $executeTime); $preparator->prepare($data, $executeTimeObj); return; } if ($isRunning) { return; } $pendingCount = $this->queueUtil->getPendingCountByScheduledJobId($id); $pendingLimit = $asSoonAsPossible ? 0 : 1; if ($pendingCount > $pendingLimit) { return; } $this->entityManager->createEntity(JobEntity::ENTITY_TYPE, [ 'name' => $scheduledJob->getName(), 'status' => Status::PENDING, 'scheduledJobId' => $id, 'executeTime' => $executeTime, ]); } private function checkAsSoonAsPossible(ScheduledJobEntity $scheduledJob): bool { return in_array($scheduledJob->getScheduling(), $this->asSoonAsPossibleSchedulingList); } private function findExecuteTime(ScheduledJobEntity $scheduledJob): ?string { $scheduling = $scheduledJob->getScheduling(); if ($scheduling === null) { return null; } $id = $scheduledJob->getId(); $asSoonAsPossible = in_array($scheduling, $this->asSoonAsPossibleSchedulingList); if ($asSoonAsPossible) { return DateTimeUtil::getSystemNowString(); } try { $cronExpression = CronExpression::factory($scheduling); } catch (Exception $e) { $this->log->error( "Scheduled Job '{$id}': Scheduling expression error: " . $e->getMessage() . '.'); return null; } try { return $cronExpression->getNextRunDate()->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT); } catch (Exception) { $this->log->error("Scheduled Job '{$id}': Unsupported scheduling expression '{$scheduling}'."); return null; } } }