Пример #1
0
 /**
  * removes all jobs from a specific queue
  * @param  string $queueName name of queue to reset
  */
 public function reset($queueName)
 {
     $count = 0;
     if ($queueName == 'failed') {
         while (ResqueProxy::redis()->lpop('failed')) {
             $count++;
         }
     } else {
         if (!in_array($queueName, $this->queues)) {
             throw new Exception("Queue {$queueName} not found");
         }
         while (ResqueProxy::pop($queueName)) {
             $count++;
         }
     }
     $this->out("Removed {$count} jobs from queue {$queueName}");
 }
Пример #2
0
 public function testEnqueuing()
 {
     $args = array('name' => 'Batman');
     ResqueProxy::enqueue('default', 'li3_resque\\tests\\mocks\\MockJob', $args);
 }
Пример #3
0
 public function run()
 {
     if (empty($this->queues)) {
         $this->queues = Environment::get('resque.queues');
     }
     if (empty($this->queues)) {
         throw new Exception('you need to define queues for the worked, either in the environment (as resque.queues) or using -queues');
     }
     if (empty($this->host)) {
         $this->host = Environment::get('resque.host');
     }
     if (empty($this->host)) {
         $this->host = 'localhost';
     }
     if (empty($this->port)) {
         $this->port = Environment::get('resque.port');
     }
     if (empty($this->port)) {
         $this->port = 6379;
     }
     if (empty($this->interval)) {
         $this->interval = 5;
     }
     if ($this->loglevel === null) {
         $this->loglevel = Environment::get('resque.loglevel');
     }
     if ($this->loglevel === null) {
         $this->loglevel = Resque_Worker::LOG_NONE;
     }
     ResqueProxy::setBackend($this->host . ':' . $this->port);
     $instance = new ResqueScheduler_Worker();
     if (!$instance) {
         throw new Exception('ResqueScheduler_Worker cant be instantiated!');
     }
     $instance->logLevel = $this->loglevel;
     $this->out("Scheduled Worker is up listening at {$this->host}:{$this->port} every {$this->interval} seconds \n");
     if (($pidfile = $this->pidfile) && $this->D) {
         $pid = file_get_contents($pidfile);
         if ($pid && !posix_kill($pid, SIGQUIT)) {
             $this->out("Error: Unable to shutdown previous worker");
             die;
         }
     }
     if ($this->D) {
         $pid = pcntl_fork();
         if (-1 == $pid) {
             $this->out("Error: Unable to fork");
             die;
         } else {
             if ($pid) {
                 // Shutdown the parent
                 $this->out("Successfully backgrounded job");
                 exit(0);
             }
         }
         // We're in the child now
         posix_setsid();
         if ($pidfile = $this->pidfile) {
             file_put_contents($pidfile, posix_getpid());
         }
         fclose(STDOUT);
         fclose(STDERR);
         fclose(STDIN);
         ob_start();
         // Capture all output
         $instance->work($this->interval);
         ob_end_flush();
     } else {
         $instance->work($this->interval);
     }
 }