Author: Michael Haynes (mike@mjphaynes.com)
Beispiel #1
0
 /**
  * Mark the current job as having failed
  * 
  * @param \Exception $e
  */
 public function fail(\Exception $e)
 {
     $this->stopped();
     $this->setStatus(Job::STATUS_FAILED, $e);
     // For the failed jobs we store a lot more data for debugging
     $packet = $this->getPacket();
     $failed_payload = array_merge(json_decode($this->payload, true), array('worker' => $packet['worker'], 'started' => $packet['started'], 'finished' => $packet['finished'], 'output' => $packet['output'], 'exception' => (array) json_decode($packet['exception'], true)));
     $this->redis->zadd(Queue::redisKey($this->queue, 'failed'), time(), json_encode($failed_payload));
     Stats::incr('failed', 1);
     Stats::incr('failed', 1, Queue::redisKey($this->queue, 'stats'));
     Event::fire(Event::JOB_FAILURE, array($this, $e));
 }
Beispiel #2
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);
         }
     }
 }