/**
  * '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()]);
 }