示例#1
0
 public function runJobs()
 {
     $cb = function ($msg) {
         $obj = unserialize($msg->body);
         echo date('Y-m-d H:i:s') . ': Running ' . get_class($obj) . '...';
         try {
             $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
             if ($obj instanceof Job) {
                 $obj->run();
             }
         } catch (\Exception $e) {
             Analog::log($e);
             echo 'Exception caught: ' . $e->getMessage() . "\n";
             $fjq = FailedJobQueue::getInstance();
             $fjq->add($obj);
         }
         echo "done\n";
     };
     $this->channel->basic_qos(null, 1, null);
     $this->channel->basic_consume($this->queue_name, '', false, false, false, false, $cb);
     try {
         while (count($this->channel->callbacks)) {
             $this->channel->wait(null, false, 240);
         }
     } catch (AMQPTimeoutException $e) {
         echo 'timing out. finished running jobs';
     }
 }
示例#2
0
 private function runFailedJobs()
 {
     $jq = \penguin\jobs\FailedJobQueue::getInstance();
     echo "starting jobs\n";
     $jq->runJobs();
 }