setName('background-queue:process'); $this->setDescription('Processes all records in the READY or TEMPORARILY_FAILED state.'); } /** * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output): int { if (!$this->tryLock()) { return 0; } $states = BackgroundJob::READY_TO_PROCESS_STATES; if ($this->backgroundQueue->getConfig()['producer']) { unset ($states[BackgroundJob::STATE_READY]); if ($this->backgroundQueue->getConfig()['waitingQueue']) { unset ($states[BackgroundJob::STATE_TEMPORARILY_FAILED]); unset ($states[BackgroundJob::STATE_WAITING]); } } $qb = $this->backgroundQueue->createQueryBuilder() ->andWhere("state IN (:state)") ->setParameter("state", $states); /** @var BackgroundJob $_entity */ foreach ($this->backgroundQueue->fetchAll($qb) as $_entity) { if ( $this->backgroundQueue->getConfig()['producer'] && $_entity->getProcessByBroker() ) { $_entity->setState(BackgroundJob::STATE_READY); $this->backgroundQueue->save($_entity); $this->backgroundQueue->publishToBroker($_entity); } else { $this->backgroundQueue->process($_entity); } } $this->tryUnlock(); return 0; } }