コード例 #1
0
ファイル: Queue.php プロジェクト: JackPrice/phpq
 /**
  * Initialise the given job object.
  * @internal
  *
  * @param Job $job
  *
  * @return void
  */
 private final function initialiseJobObject(Job &$job)
 {
     $created = new DateTimeImmutable();
     Reflection\JobReflector::setQueue($job, $this);
     Reflection\JobReflector::setCreated($job, $created);
     Reflection\JobReflector::setSchedule($job, $created);
     Reflection\JobReflector::setTimeout($job, null);
     Reflection\JobReflector::setVersion($job, 0);
     return;
 }
コード例 #2
0
ファイル: DoctrineDBALDriver.php プロジェクト: JackPrice/phpq
 /**
  * Create a job from te given column set.
  *
  * @param $columns
  *
  * @return Job
  * @throws ReflectionException
  */
 private function hydrateJobObject($columns)
 {
     // Figure out the class of the job
     $class = $columns[$this->columns['__CLASS__']];
     if (!class_exists($class)) {
         throw new ReflectionException(sprintf('Job class [%s] does not exist', $class));
     }
     try {
         $job = new $class();
     } catch (\Exception $e) {
         throw new ReflectionException(sprintf('Could not instantiate object of type [%s]', $class));
     }
     if (!$job instanceof Job) {
         throw new ReflectionException(sprintf('[%s] is not an instance of %s', $class, Job::class));
     }
     $queue = $this->getPHPQ()->getQueue($columns[$this->columns[JobReflector::PROPERTY_QUEUE]]);
     $parameters = $columns[$this->columns[JobReflector::PROPERTY_PARAMETERS]];
     $result = $columns[$this->columns[JobReflector::PROPERTY_RESULT]];
     $timeout = $columns[$this->columns[JobReflector::PROPERTY_TIMEOUT]];
     $lastAttempt = $columns[$this->columns[JobReflector::PROPERTY_LAST_ATTEMPT]];
     JobReflector::setId($job, $columns[$this->columns[JobReflector::PROPERTY_ID]]);
     JobReflector::setQueue($job, $queue);
     JobReflector::setCreated($job, new DateTimeImmutable($columns[$this->columns[JobReflector::PROPERTY_CREATED]]));
     JobReflector::setSchedule($job, new DateTimeImmutable($columns[$this->columns[JobReflector::PROPERTY_SCHEDULE]]));
     JobReflector::setFailed($job, $columns[$this->columns[JobReflector::PROPERTY_FAILED]]);
     JobReflector::setFinished($job, $columns[$this->columns[JobReflector::PROPERTY_FINISHED]]);
     JobReflector::setResult($job, $result ? json_decode($result, true) : null);
     JobReflector::setProgress($job, $columns[$this->columns[JobReflector::PROPERTY_PROGRESS]]);
     JobReflector::setLastAttempt($job, $lastAttempt ? new DateTimeImmutable($lastAttempt) : null);
     JobReflector::setTimeout($job, $timeout ? new DateTimeImmutable($timeout) : null);
     JobReflector::setRetryCount($job, $columns[$this->columns[JobReflector::PROPERTY_RETRY_COUNT]]);
     JobReflector::setParameters($job, $parameters ? json_decode($parameters, true) : array());
     // Track the state of this job
     $this->jobs[spl_object_hash($job)] = clone $job;
     return $job;
 }