示例#1
0
文件: Job.php 项目: junthink/resque
 /**
  * Create a new job and save it to the specified queue.
  *
  * @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.
  * @param boolean $monitor Set to true to be able to monitor the status of a job.
  * @param string $id Unique identifier for tracking the job. Generated if not supplied.
  *
  * @return string
  */
 public static function create($queue, $class, $args = null, $monitor = false, $id = null)
 {
     if (is_null($id)) {
         $id = Resque::generateJobId();
     }
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     Resque::push($queue, array('class' => $class, 'args' => array($args), 'id' => $id, 'queue_time' => microtime(true)));
     if ($monitor) {
         Status::create($id);
     }
     return $id;
 }
示例#2
0
 /**
  * Create a new job and save it to the specified queue.
  *
  * @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.
  * @param boolean $trackStatus Set to true to be able to monitor the status of a job.
  *
  * @return string|boolean Job ID when the job was created, false if creation was cancelled due to beforeEnqueue
  */
 public static function enqueue($queue, $class, $args = null, $trackStatus = false)
 {
     $id = Resque::generateJobId();
     $hookParams = ['class' => $class, 'args' => $args, 'queue' => $queue, 'id' => $id];
     try {
         Event::trigger('beforeEnqueue', $hookParams);
     } catch (Job\DontCreate $e) {
         return false;
     }
     Job::create($queue, $class, $args, $trackStatus, $id);
     Event::trigger('afterEnqueue', $hookParams);
     return $id;
 }