logger->notice('Grabbing pending jobs.'); $response = $this->communicator->get('/jobs/pending'); $body = $response->getBody()->getContents(); if (trim($body) === '') { return []; } return json_decode($body)->jobs; } protected function runJob($job): bool { $base_command = '/app/bin/emails'; $cmd = [$base_command, $job->command]; if ($job->arguments !== '') { $cmd []= $job->arguments; } $cmd = implode(' ', $cmd); $this->logger->notice("Running '{$cmd}'"); $response = shell_exec($cmd); $this->logger->info("Result: {$response}"); return $response !== false; } public function execute(InputInterface $input, OutputInterface $output) { $section1 = $output->section(); $section2 = $output->section(); $io1 = new SymfonyStyle($input, $section1); $io2 = new SymfonyStyle($input, $section2); $io1->title('Checking Pending Jobs'); $pending_jobs = $this->getPendingJobs(); $notice = 'Found ' . count($pending_jobs) . ' jobs'; $io1->text($notice); $this->logger->info($notice); if (count($pending_jobs) > 0) { $io1->section('Running Jobs'); $io1->progressStart(count($pending_jobs)); foreach ($pending_jobs as $job) { $section2->clear(); $io2->text("Running {$job->command}"); if ($this->runJob($job)) { $io2->success('Success'); } else { $io2->error('Failure'); } $io1->progressAdvance(); } } $section2->clear(); $io2->success('Done'); return Command::SUCCESS; } }