/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->checkRun()) {
         return;
     }
     try {
         $this->status->toggleUpdateInProgress();
     } catch (\RuntimeException $e) {
         $this->status->add($e->getMessage());
         return;
     }
     try {
         while (!empty($this->queue->peek()) && strpos($this->queue->peek()[Queue::KEY_JOB_NAME], 'setup:') === 0) {
             $job = $this->queue->popQueuedJob();
             $this->status->add(sprintf('Job "%s" has started' . PHP_EOL, $job));
             try {
                 $job->execute();
                 $this->status->add(sprintf('Job "%s" has been successfully completed', $job));
             } catch (\Exception $e) {
                 $this->status->toggleUpdateError(true);
                 $this->status->add(sprintf('An error occurred while executing job "%s": %s', $job, $e->getMessage()));
             }
         }
     } catch (\Exception $e) {
         $this->status->add($e->getMessage());
         $this->status->toggleUpdateError(true);
     } finally {
         $this->status->toggleUpdateInProgress(false);
     }
 }
 /**
  * Executes setup jobs from the queue
  *
  * @return int
  */
 private function executeJobsFromQueue()
 {
     $returnCode = \Magento\Framework\Console\Cli::RETURN_SUCCESS;
     try {
         while (!empty($this->queue->peek()) && strpos($this->queue->peek()[Queue::KEY_JOB_NAME], 'setup:') === 0) {
             $job = $this->queue->popQueuedJob();
             $this->status->add(sprintf('Job "%s" has started' . PHP_EOL, $job), \Psr\Log\LogLevel::INFO);
             try {
                 $job->execute();
                 $this->status->add(sprintf('Job "%s" has been successfully completed', $job), \Psr\Log\LogLevel::INFO);
             } catch (\Exception $e) {
                 $this->status->toggleUpdateError(true);
                 $this->status->add(sprintf('An error occurred while executing job "%s": %s', $job, $e->getMessage()), \Psr\Log\LogLevel::ERROR);
                 $returnCode = \Magento\Framework\Console\Cli::RETURN_FAILURE;
             }
         }
     } catch (\Exception $e) {
         $this->status->add($e->getMessage(), \Psr\Log\LogLevel::ERROR);
         $this->status->toggleUpdateError(true);
         $returnCode = \Magento\Framework\Console\Cli::RETURN_FAILURE;
     } finally {
         $this->status->toggleUpdateInProgress(false);
     }
     return $returnCode;
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage "jobs" field is missing or is not an array
  */
 public function testPeekExceptionNoJobsKey()
 {
     $this->reader->expects($this->once())->method('read')->willReturn('{"foo": "bar"}');
     $this->queue->peek();
 }