Resque\Job::loadPayload PHP Method

loadPayload() public static method

Load a job from the Redis payload
public static loadPayload ( string $queue, string $payload ) : string
$queue string The name of the queue to place the job in
$payload string The payload that was stored in Redis
return string
    public static function loadPayload($queue, $payload)
    {
        $payload = json_decode($payload, true);
        if (!is_array($payload) or !count($payload)) {
            throw new \InvalidArgumentException('Supplied $payload must be a json encoded array.');
        }
        return new static($queue, $payload['id'], $payload['class'], $payload['data']);
    }

Usage Example

Esempio n. 1
0
 /**
  * Find any delayed jobs and add them to the queue if found
  *
  * @param int $endTime optional end time for range
  * @param int $startTime optional start time for range
  */
 public function queueDelayed($endTime = null, $startTime = 0)
 {
     $startTime = $startTime ?: 0;
     $endTime = $endTime ?: time();
     foreach ($this->resolveQueues() as $queue) {
         $this->redis->multi();
         $jobs = $this->redis->zrangebyscore(Queue::redisKey($queue, 'delayed'), $startTime, $endTime);
         $this->redis->zremrangebyscore(Queue::redisKey($queue, 'delayed'), $startTime, $endTime);
         list($jobs, $found) = $this->redis->exec();
         if ($found > 0) {
             foreach ($jobs as $payload) {
                 $job = Job::loadPayload($queue, $payload);
                 $job->setWorker($this);
                 if (Event::fire(Event::JOB_QUEUE_DELAYED, $job) !== false) {
                     $job->queue();
                     Event::fire(Event::JOB_QUEUED_DELAYED, $job);
                 }
             }
             Stats::decr('delayed', $found);
             Stats::decr('delayed', $found, Queue::redisKey($queue, 'stats'));
             $this->log('Added <pop>' . $found . '</pop> delayed job' . ($found == 1 ? '' : 's') . ' to <pop>' . $queue . '</pop> queue', Logger::NOTICE);
         }
     }
 }
All Usage Examples Of Resque\Job::loadPayload