/** * Push a new job onto the queue after a delay. * * @param \DateTime|int $delay * @param string $job * @param mixed $data * @param string $queue * @return mixed */ public function later($delay, $job, $data = '', $queue = null) { $payload = $this->createPayload($job, $data); $req = new SendMessage($this->getQueue($queue)); $req->setMessageBody($payload); $req->setDelaySeconds($this->getSeconds($delay)); /** * @var $res SendMessageRes */ $res = $req->send(); return $res->getMessageId(); }
/** * @param SendMessage $req * @throws ParameterException */ public static function validate($req) { self::queueNameValidate($req->getQueueName()); self::validateString($messageBody = $req->getMessageBody()); self::validateNumber($delaySeconds = $req->getDelaySeconds()); self::validateNumber($priority = $req->getPriority()); if (!$messageBody) { throw new ParameterException('MessageBodyInvalid', 'Bad value: "", message body should not be None.'); } if ($delaySeconds != -1 && $delaySeconds < 0 & $delaySeconds > 604800) { throw new ParameterException('DelaySecondsInvalid', sprintf('Bad value: "%d", delay_seconds should between 0 and 604800.', $delaySeconds)); } if ($priority != -1 && $priority < 0) { throw new ParameterException('PriorityInvalid', sprintf('Bad value: "%d", priority should larger than 0.', $priority)); } }