public function testPutJob() { $beanstalk = new Beanstalk(); $beanstalk->useTube('test'); $job = new Job(); $job->setData(['foo' => 23, 'bar' => 42]); $this->assertNull($job->getId()); $beanstalk->putJob($job); $this->assertNotNull($job->getId()); }
/** * @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); } }