Create a new job and save it to the specified queue.
public static create ( string $queue, string $class, array $args = null, boolean $monitor = false, string $id = null ) : string | ||
$queue | string | The name of the queue to place the job in. |
$class | string | The name of the class that contains the code to execute the job. |
$args | array | Any optional arguments that should be passed when the job is executed. |
$monitor | boolean | Set to true to be able to monitor the status of a job. |
$id | string | Unique identifier for tracking the job. Generated if not supplied. |
return | string |
/** * Create a new job and save it to the specified queue. * 创建一个Job并将它放入到队列中 * * @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 */ public static function enqueue($queue, $class, $args = null, $trackStatus = false) { require_once dirname(__FILE__) . '/Resque/Job.php'; // 创建job $result = Resque_Job::create($queue, $class, $args, $trackStatus); if ($result) { // 触发入队的事件 Resque_Event::trigger('afterEnqueue', array('class' => $class, 'args' => $args, 'queue' => $queue)); } return $result; }
/** * 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 */ public static function enqueue($queue, $class, $args = null, $trackStatus = false) { $result = Resque_Job::create($queue, $class, $args, $trackStatus); if ($result) { Resque_Event::trigger('afterEnqueue', array('class' => $class, 'args' => $args, 'queue' => $queue)); } return $result; }
public static function enqueue($queue, $class, $args=array(), $trackStatus = false) { require_once dirname(__FILE__).'/Resque/Job.php'; return Resque_Job::create($queue, $class, $args, $trackStatus); }
/** * 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 = array('class' => $class, 'args' => $args, 'queue' => $queue, 'id' => $id); try { Resque_Event::trigger('beforeEnqueue', $hookParams); } catch (Resque_Job_DontCreate $e) { return false; } Resque_Job::create($queue, $class, $args, $trackStatus, $id); Resque_Event::trigger('afterEnqueue', $hookParams); return $id; }
/** * 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) { if (self::$runInBackground) { $id = Resque::generateJobId(); $hookParams = array('class' => $class, 'args' => $args, 'queue' => $queue, 'id' => $id); try { Resque_Event::trigger('beforeEnqueue', $hookParams); } catch (Resque_Job_DontCreate $e) { return false; } Resque_Job::create($queue, $class, $args, $trackStatus, $id); Resque_Event::trigger('afterEnqueue', $hookParams); return $id; } else { $obj = new $class(); $obj->args = $args; if (method_exists($obj, 'setUp')) { $obj->setUp(); } if (method_exists($obj, 'perform')) { $obj->perform(); } if (method_exists($obj, 'tearDown')) { $obj->tearDown(); } return true; } }