Ejemplo n.º 1
0
 /**
  * Enqueue a job for execution at a given timestamp.
  *
  * Identical to Resque::enqueue, however the first argument is a timestamp
  * (either UNIX timestamp in integer format or an instance of the DateTime
  * class in PHP).
  *
  * @param DateTime|int $at    Instance of PHP DateTime object or int of UNIX timestamp.
  * @param string       $queue The name of the queue to place the job in.
  * @param string       $class The name of the class that contains the code to execute the job.
  * @param array        $args  Any optional arguments that should be passed when the job is executed.
  */
 public static function enqueueAt($at, $queue, $class, $args = array())
 {
     self::validateJob($class, $queue);
     $job = self::jobToHash($queue, $class, $args);
     self::delayedPush($at, $job);
     Event::trigger('afterSchedule', array('at' => $at, 'queue' => $queue, 'class' => $class, 'args' => $args));
 }
Ejemplo n.º 2
0
 /**
  * Schedule all of the delayed jobs for a given timestamp.
  *
  * Searches for all items for a given timestamp, pulls them off the list of
  * delayed jobs and pushes them across to Resque.
  *
  * @param DateTime|int $timestamp Search for any items up to this timestamp to schedule.
  */
 public function enqueueDelayedItemsForTimestamp($timestamp)
 {
     $item = null;
     while ($item = Scheduler::nextItemForTimestamp($timestamp)) {
         $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] . ' [delayed]');
         if (!empty($item['args'])) {
             $item['args'] = reset($item['args']);
         }
         Event::trigger('beforeDelayedEnqueue', array('queue' => $item['queue'], 'class' => $item['class'], 'args' => $item['args']));
         Resque::enqueue($item['queue'], $item['class'], $item['args']);
     }
 }
Ejemplo n.º 3
0
 /**
  * Mark the current job as having failed.
  *
  * @param $exception
  */
 public function fail($exception)
 {
     Event::trigger('onFailure', array('exception' => $exception, 'job' => $this));
     $this->updateStatus(Status::STATUS_FAILED);
     Failure::create($this->payload, $exception, $this->worker, $this->queue);
     Stat::incr('failed');
     Stat::incr('failed:' . $this->worker);
 }
Ejemplo n.º 4
0
 /**
  * Perform necessary actions to start a worker.
  */
 private function startup()
 {
     $this->registerSigHandlers();
     $this->pruneDeadWorkers();
     Event::trigger('beforeFirstFork', $this);
     $this->registerWorker();
 }