/** * Pop job queue. * * @return AbstractJob|null * @throws \RuntimeException */ public function popQueuedJob() { $job = null; $queue = json_decode($this->reader->read(), true); if (!is_array($queue)) { return $job; } if (isset($queue[self::KEY_JOBS]) && is_array($queue[self::KEY_JOBS])) { $this->validateJobDeclaration($queue[self::KEY_JOBS][0]); $job = $this->jobFactory->create($queue[self::KEY_JOBS][0][self::KEY_JOB_NAME], $queue[self::KEY_JOBS][0][self::KEY_JOB_PARAMS]); array_shift($queue[self::KEY_JOBS]); if (empty($queue[self::KEY_JOBS])) { $this->writer->write(''); } else { $this->writer->write(json_encode($queue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); } } else { throw new \RuntimeException(sprintf('"%s" field is missing or is not an array.', self::KEY_JOBS)); } return $job; }