Exemple #1
0
 /**
  * @param Job $job
  * @throws RuntimeException
  */
 public function putJob(Job $job)
 {
     $message = vsprintf('put %u %u %u %u', [$job->getPriority(), $job->getDelay(), $job->getTtr(), strlen($job)]);
     $this->write($message);
     $this->write($job);
     $status = $this->readStatus();
     switch ($status[0]) {
         case 'INSERTED':
             $job->setId($status[1]);
             return $this;
         case 'BURIED':
             $job->setId($status[1]);
             return $this;
         case 'EXPECTED_CRLF':
             throw new RuntimeException('The job body must be followed by a CR-LF pair.');
         case 'JOB_TOO_BIG':
             throw new RuntimeException('The client has requested to put a job with a body larger than max-job-size bytes.');
         case 'DRAINING':
             throw new RuntimeException('The server has been put into "drain mode" and is no longer accepting new jobs.');
         default:
             throw new RuntimeException($status);
     }
 }