Exemple #1
0
 /**
  * @param SocketInterface $socket
  * @return integer
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $socket->write($this->data);
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'INSERTED':
         case 'BURIED':
             return (int) strtok(' ');
             // job id
         // job id
         case 'EXPECTED_CRLF':
         case 'JOB_TOO_BIG':
         case 'DRAINING':
         default:
             throw new CommandException("Put failed '{$status}'");
     }
 }
Exemple #2
0
 /**
  * @param SocketInterface $socket
  * @return integer
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'KICKED':
             return (int) strtok(' ');
         default:
             throw new CommandException("Kick with bound '{$this->bound}' failed '{$status}'");
     }
 }
Exemple #3
0
 /**
  * @param SocketInterface $socket
  * @return integer
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'WATCHING':
             return (int) strtok(' ');
         default:
             throw new CommandException("Watch tube '{$this->tube}' failed '{$status}'");
     }
 }
Exemple #4
0
 /**
  * @param SocketInterface $socket
  * @return string
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write('list-tube-used');
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'USING':
             return strtok(' ');
         default:
             throw new CommandException("List tube used failed '{$status}'");
     }
 }
Exemple #5
0
 /**
  * @param SocketInterface $socket
  * @return $this
  * @throws NotFoundException
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $status = $socket->read();
     switch ($status) {
         case 'TOUCHED':
             return $this;
         case 'NOT_TOUCHED':
             throw new NotFoundException("Job id '{$this->id}' could not be found.");
         default:
             throw new CommandException("Touch id '{$this->id}' failed '{$status}'");
     }
 }
Exemple #6
0
 /**
  * @param SocketInterface $socket
  * @return $this
  * @throws NotFoundException
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $response = $socket->read();
     switch ($response) {
         case 'DELETED':
             return $this;
         case 'NOT_FOUND':
             throw new NotFoundException("Job id '{$this->id}' could not be found.");
         default:
             throw new CommandException("Delete id '{$this->id}' failed '{$response}'");
     }
 }
Exemple #7
0
 /**
  * @param SocketInterface $socket
  * @return integer
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'WATCHING':
             return (int) strtok(' ');
         case 'NOT_IGNORED':
             throw new CommandException('Can not ignore only tube currently watching.');
         default:
             throw new CommandException("Ignore tube '{$this->tube}' failed '{$status}'");
     }
 }
Exemple #8
0
 /**
  * @param SocketInterface $socket
  * @return string
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'USING':
             return strtok(' ');
             // tube name
         // tube name
         default:
             throw new CommandException("Use tube '{$this->tube}' failed '{$status}'");
     }
 }
Exemple #9
0
 /**
  * @param SocketInterface $socket
  * @return array
  * @throws NotFoundException
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'OK':
             $data = substr($socket->read((int) strtok(' ') + 2), 0, -2);
             return $this->decode($data);
         case 'NOT_FOUND':
             throw new NotFoundException("Stats read could not find specified job");
         default:
             throw new CommandException("Stats read failed '{$status}'");
     }
 }
Exemple #10
0
 /**
  * @param SocketInterface $socket
  * @return array
  * @throws NotFoundException
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $response = strtok($socket->read(), ' ');
     switch ($response) {
         case 'FOUND':
             $id = (int) strtok(' ');
             $bytes = (int) strtok(' ');
             $body = substr($socket->read($bytes + 2), 0, -2);
             return ['id' => $id, 'body' => $body];
         case 'NOT_FOUND':
             throw new NotFoundException("Peek failed to find any jobs");
         default:
             throw new CommandException("Unknown peek response '{$response}'");
     }
 }
Exemple #11
0
 /**
  * @param SocketInterface $socket
  * @return array|false
  * @throws CommandException
  */
 public function process(SocketInterface $socket)
 {
     $socket->write($this->getCommand());
     $status = strtok($socket->read(), ' ');
     switch ($status) {
         case 'RESERVED':
             $id = (int) strtok(' ');
             $bytes = (int) strtok(' ');
             $body = substr($socket->read($bytes + 2), 0, -2);
             return ['id' => $id, 'body' => $body];
         case 'DEADLINE_SOON':
         case 'TIMED_OUT':
             return false;
         default:
             throw new CommandException("Reserve failed '{$status}'");
     }
 }