Beispiel #1
0
 /**
  * @param array $jobs
  * @return void
  */
 public function addJobs(array $jobs)
 {
     foreach ($jobs as $job) {
         $this->validateJobDeclaration($job);
         $queue = json_decode($this->reader->read(), true);
         $queue[self::KEY_JOBS][] = $job;
         $this->writer->write(json_encode($queue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     }
 }
 /**
  * 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;
 }