logger->debug("Running {$this->getName()}"); $io = new Console\Style\SymfonyStyle($input, $output); $now = new DateTimeImmutable(); $io->title("[{$now->format('Y-m-d H:i:s e')}] Running Queue..."); $jobs = $this->getJobs($output); if (is_int($jobs)) { return $jobs; } return $this->runJobs($output, $jobs); } protected function getJobs(Console\Output\OutputInterface $output): int|array { $uri = '/api/queue/jobs'; $output->writeln("GET {$uri}"); $response = $this->client->get($uri); $output->writeln("Response Code: {$response->getStatusCode()}"); if ($response->getStatusCode() !== 200) { return Console\Command\Command::FAILURE; } $contents = $response->getBody()->getContents(); if (empty($contents)) { return []; } return json_decode($contents, true)['jobs']; } protected function runJobs(Console\Output\OutputInterface $output, array $jobs): int { $errors = 0; foreach ($jobs as $job) { if ($this->runJob($output, $job) === Console\Command\Command::FAILURE) { $errors ++; } } return $errors === 0 ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE; } protected function runJob(Console\Output\OutputInterface $output, int $job_id): int { $uri = "/api/queue/run/{$job_id}"; $output->writeln("GET {$uri}"); $response = $this->client->get($uri); $output->writeln("Response Code: {$response->getStatusCode()}"); return ((int) floor($response->getStatusCode() / 100) === 2) ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE; } }