diff options
Diffstat (limited to 'intern.gospeladlershof.de/vendor/pda/pheanstalk/src/Command/ReserveCommand.php')
| -rw-r--r-- | intern.gospeladlershof.de/vendor/pda/pheanstalk/src/Command/ReserveCommand.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/intern.gospeladlershof.de/vendor/pda/pheanstalk/src/Command/ReserveCommand.php b/intern.gospeladlershof.de/vendor/pda/pheanstalk/src/Command/ReserveCommand.php new file mode 100644 index 0000000..9d4ccc8 --- /dev/null +++ b/intern.gospeladlershof.de/vendor/pda/pheanstalk/src/Command/ReserveCommand.php @@ -0,0 +1,62 @@ +<?php + +namespace Pheanstalk\Command; + +use Pheanstalk\Response; + +/** + * The 'reserve' command. + * Reserves/locks a ready job in a watched tube. + * + * @author Paul Annesley + * @package Pheanstalk + * @license http://www.opensource.org/licenses/mit-license.php + */ +class ReserveCommand + extends AbstractCommand + implements \Pheanstalk\ResponseParser +{ + private $_timeout; + + /** + * A timeout value of 0 will cause the server to immediately return either a + * response or TIMED_OUT. A positive value of timeout will limit the amount of + * time the client will block on the reserve request until a job becomes + * available. + * + * @param int $timeout + */ + public function __construct($timeout = null) + { + $this->_timeout = $timeout; + } + + /* (non-phpdoc) + * @see Command::getCommandLine() + */ + public function getCommandLine() + { + return isset($this->_timeout) ? + sprintf('reserve-with-timeout %s', $this->_timeout) : + 'reserve'; + } + + /* (non-phpdoc) + * @see ResponseParser::parseResponse() + */ + public function parseResponse($responseLine, $responseData) + { + if ($responseLine === Response::RESPONSE_DEADLINE_SOON || + $responseLine === Response::RESPONSE_TIMED_OUT) + { + return $this->_createResponse($responseLine); + } + + list($code, $id) = explode(' ', $responseLine); + + return $this->_createResponse($code, array( + 'id' => (int) $id, + 'jobdata' => $responseData, + )); + } +} |
