Exemplo n.º 1
0
 /**
  * Pop all updater application queued jobs.
  * 
  * Note, that this method is not idempotent, queue will be cleared after its execution
  *
  * @return AbstractJob[]
  * @throws \RuntimeException
  */
 public function popQueuedJobs()
 {
     $jobs = [];
     $queue = json_decode($this->reader->read(), true);
     if (!is_array($queue)) {
         return $jobs;
     }
     if (isset($queue[self::KEY_JOBS]) && is_array($queue[self::KEY_JOBS])) {
         /** @var object $job */
         foreach ($queue[self::KEY_JOBS] as $job) {
             $this->validateJobDeclaration($job);
             $jobs[] = $this->jobFactory->create($job[self::KEY_JOB_NAME], $job[self::KEY_JOB_PARAMS]);
         }
     } else {
         throw new \RuntimeException(sprintf('"%s" field is missing or is not an array.', self::KEY_JOBS));
     }
     $this->reader->clearQueue();
     return $jobs;
 }
Exemplo n.º 2
0
 /**
  * Pop job queue.
  *
  * @return AbstractJob
  * @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;
 }
 public function testCreateInvalidJob()
 {
     $this->setExpectedException('\\RuntimeException', '"invalid" job is not supported.');
     $this->jobFactory->create('invalid', []);
 }