Exemple #1
0
 /**
  * Check the queue from Beanstalk and send the notifications scheduled there
  *
  * @see at https://docs.phalconphp.com/en/latest/api/Phalcon_Queue_Beanstalk.html
  */
 public function consumeQueue()
 {
     while (true) {
         while ($this->queue->peekReady() !== false) {
             $job = $this->queue->reserve();
             $message = $job->getBody();
             foreach ($message as $userId => $id) {
                 $notification = Notifications::findFirstById($id);
                 if ($notification) {
                     $this->send($notification);
                 }
             }
             if (is_object($this->transport)) {
                 $this->transport->stop();
                 $this->transport = null;
                 $this->mailer = null;
             }
             $job->delete();
         }
         sleep(5);
     }
 }