Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function enqueue(MailJobInterface $mailJob)
 {
     if (null !== $this->getCypher()) {
         $mailJob->setMessage($this->getCypher()->encodeMailMessage($mailJob->getMessage()));
     }
     return $this->adapter->enqueue($mailJob);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function enqueue(MailJobInterface $mailJob)
 {
     $message = $mailJob->getMessage();
     if (null !== $this->getCypher() && $message instanceof MailMessage) {
         $mailJob->setMessage($this->getCypher()->encodeMailMessage($message));
     }
     return $this->adapter->enqueue($mailJob);
 }
 /**
  * @param MailJobInterface|SqsMailJob $mailJob
  *
  * @return bool
  */
 public function ack(MailJobInterface $mailJob)
 {
     if ($mailJob->isNewRecord()) {
         throw new InvalidCallException('SqsMailJob cannot be a new object to be acknowledged');
     }
     if ($mailJob->getDeleted()) {
         $this->getConnection()->getInstance()->deleteMessage(['QueueUrl' => $this->queueUrl, 'ReceiptHandle' => $mailJob->getReceiptHandle()]);
         return true;
     } elseif ($mailJob->getVisibilityTimeout() !== null) {
         $this->getConnection()->getInstance()->changeMessageVisibility(['QueueUrl' => $this->queueUrl, 'ReceiptHandle' => $mailJob->getReceiptHandle(), 'VisibilityTimeout' => $mailJob->getVisibilityTimeout()]);
         return true;
     }
     return false;
 }
 /**
  * 'Ack'knowledge the MailJob. Once a MailJob as been processed it could be:.
  *
  * - Updated its status to 'C'ompleted
  * - Updated its status to 'N'ew and set its `timeToSend` attribute to a future date
  *
  * @param MailJobInterface|PdoMailJob $mailJob
  *
  * @return bool
  */
 public function ack(MailJobInterface $mailJob)
 {
     if ($mailJob->isNewRecord()) {
         throw new InvalidCallException('PdoMailJob cannot be a new object to be acknowledged');
     }
     $sqlText = 'UPDATE `%s`
             SET `attempt`=:attempt, `state`=:state, `timeToSend`=:timeToSend, `sentTime`=:sentTime
             WHERE `id`=:id';
     $sql = sprintf($sqlText, $this->tableName);
     $sentTime = $mailJob->isCompleted() ? date('Y-m-d H:i:s', time()) : null;
     $query = $this->getConnection()->getInstance()->prepare($sql);
     $query->bindValue(':id', $mailJob->getId(), PDO::PARAM_INT);
     $query->bindValue(':attempt', $mailJob->getAttempt(), PDO::PARAM_INT);
     $query->bindValue(':state', $mailJob->getState());
     $query->bindValue(':timeToSend', $mailJob->getTimeToSend());
     $query->bindValue(':sentTime', $sentTime);
     return $query->execute();
 }
 /**
  * @param RedisMailJob|MailJobInterface $mailJob
  *
  * @return string
  */
 protected function createPayload(MailJobInterface $mailJob)
 {
     return json_encode(['id' => $mailJob->isNewRecord() ? sha1(Random::string(32)) : $mailJob->getId(), 'attempt' => $mailJob->getAttempt(), 'message' => $mailJob->getMessage()]);
 }