/** * Set Notify users that always want notifications via Queueing jobs * * @param integer $userId user want notification * @param integer $postId [description] * @param integer $postReplyId [description] * @param string $type Such as Comment, reply... * * @return integet|bool */ public function setNotification($userId, $postId, $postReplyId, $type) { $notification = new Notifications(); $notification->setUsersId($userId); $notification->setPostsId($postId); $notification->setPostsReplyId($postReplyId); $notification->setType($type); if (!$notification->save()) { $messages = $notification->getMessages(); error_log('setNotification error' . __LINE__ . $messages[0]); return false; } return $notification->getId(); }
/** * 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); } }