Esempio n. 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.');
     }
     if (isset($args['id'])) {
         $id = $args['id'];
         unset($args['id']);
     } else {
         $id = md5(uniqid('', true));
     }
     Resque::push($queue, array('class' => $class, 'args' => array($args), 'id' => $id));
     return $id;
 }
Esempio n. 2
0
 public function pruneDeadWorkers()
 {
     $worker_pids = $this->workerPids();
     return Resque::redis()->smembers('workers')->then(function ($response) use($worker_pids) {
         $promises = \React\Promise\map($response, function ($workerId) use($worker_pids) {
             list($hostname, $pid, $queues) = explode(':', $workerId, 3);
             if ($hostname != $this->hostname || in_array($pid, $worker_pids) || $pid == getmypid()) {
                 return null;
             }
             $queues = explode(',', $queues);
             $worker = new self($queues, \Iwai\React\Resque::getEventLoop());
             $worker->setId($workerId);
             return $worker->unregisterWorker();
         });
         return \React\Promise\all($promises);
     });
 }