コード例 #1
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 $monitor Set to true to be able to monitor the status of a job.
  *
  * @return string
  */
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $new = true;
     if (isset($args['id'])) {
         $id = $args['id'];
         unset($args['id']);
         $new = false;
     } else {
         $id = md5(uniqid('', true));
     }
     if (empty($args)) {
         $args = [];
     }
     Resque::push($queue, array('class' => $class, 'args' => array($args), 'id' => $id));
     if ($monitor) {
         if ($new) {
             Resque_Job_Status::create($id);
         } else {
             $statusInstance = new Resque_Job_Status($id);
             $statusInstance->update($id, Resque_Job_Status::STATUS_WAITING);
         }
     }
     return $id;
 }
コード例 #2
0
ファイル: Job.php プロジェクト: hungnv0789/vhtm
	/**
	 * 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|callback $method The name of the class that contains the code to execute the job, or an array containing a class name and method name
	 * @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 $include Path to a file to include before attempting to execute the callback
	 */
	public static function create($queue, $method, array $args=array(), $monitor = false, $include = '')
	{
		if (is_array($method)) {
			$class = $method[0];
			$method = $method[1];
		} else {
			$class = '';
		}

		$id = md5(uniqid('', true));

		$payload = array(
			'class' => $class,
			'method' => $method,
			'args' => $args,
			'id' => $id,
			'include' => $include,
		);

		Resque::push($queue, $payload);

		if($monitor) {
			Resque_Job_Status::create($id);
		}

		return $id;
	}
コード例 #3
0
ファイル: JobStatusTest.php プロジェクト: zhangsong/yii
 public function testStatusTrackingCanBeStopped()
 {
     Resque_Job_Status::create('test');
     $status = new Resque_Job_Status('test');
     $this->assertEquals(Resque_Job_Status::STATUS_WAITING, $status->get());
     $status->stop();
     $this->assertFalse($status->get());
 }
コード例 #4
0
ファイル: Job.php プロジェクト: Rming/novophp
 /**
  * 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.
  */
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $id = md5(uniqid('', true));
     Resque::push($queue, array('class' => $class, 'args' => $args, 'id' => $id));
     if ($monitor) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
コード例 #5
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.
  * @param   boolean      $trackStatus   Set to true to be able to monitor the status of a job.
  * @return  string                      Job ID
  */
 public static function enqueueAt($at, $queue, $class, $args = array(), $trackStatus = false)
 {
     self::validateJob($class, $queue);
     $args['id'] = md5(uniqid('', true));
     $args['s_time'] = time();
     $job = self::jobToHash($queue, $class, $args, $trackStatus);
     self::delayedPush($at, $job);
     if ($trackStatus) {
         \Resque_Job_Status::create($args['id'], Job\Status::STATUS_SCHEDULED);
     }
     \Resque_Event::trigger('afterSchedule', array('at' => $at, 'queue' => $queue, 'class' => $class, 'args' => $args));
     return $args['id'];
 }
コード例 #6
0
ファイル: Job.php プロジェクト: SoftwarePunt/php-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) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
コード例 #7
0
ファイル: Closure.php プロジェクト: snikius/php-resque
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $id = md5(uniqid('', true));
     $data = array('class' => $class, 'args' => array($args), 'id' => $id, 'closure' => true, 'queue_time' => microtime(true));
     Log::info('Push closure:' . json_encode($data));
     Resque::push($queue, $data);
     if ($monitor) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
コード例 #8
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 $monitor Set to true to be able to monitor the status of a job.
  *
  * @return string
  */
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     // uniqid — 生成一个唯一ID,一个带前缀、基于当前时间微秒数的唯一ID
     $id = md5(uniqid('', true));
     // 将相应的类名/参数和id入队
     Resque::push($queue, array('class' => $class, 'args' => array($args), 'id' => $id));
     if ($monitor) {
         // 创建job的状态,以便监控这个job
         Resque_Job_Status::create($id);
     }
     return $id;
 }