/**
- Reserve a job (with a timeout).
-
- @param integer $timeout If given specifies number of seconds to wait for
- a job.
0 returns immediately.
- @return array|false
false on error otherwise an array holding job id
- and body.
*/
public function reserve($timeout = null) {
if (isset($timeout)) {
$this->_write(sprintf('reserve-with-timeout %d',$timeout));
} else {
$this->_write('reserve');
}
$status = strtok($this->_read(),' ');
switch ($status) {
case 'RESERVED':
return [
'id' => (integer) strtok(' '),'body' => $this->_read((integer) strtok(' '))
];
case 'DEADLINE_SOON':
case 'TIMED_OUT':
default:
$this->_error($status);
return false;
}
}
/**
- Removes a job from the server entirely.
-
- @param integer $id The id of the job.
- @return boolean
false on error,true on success.
*/
public function delete($id) {
$this->_write(sprintf('delete %d',$id));
$status = $this->_read();
switch ($status) {
case 'DELETED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/**
- Puts a reserved job back into the ready queue.
-
- @param integer $id The id of the job.
- @param integer $pri Priority to assign to the job.
- @param integer $delay Number of seconds to wait before putting the job in the ready queue.
- @return boolean
false on error,true on success.
*/
public function release($id,$delay) {
$this->_write(sprintf('release %d %d %d',$id,$delay));
$status = $this->_read();
switch ($status) {
case 'RELEASED':
case 'BURIED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/**
- Puts a job into the
buried state Buried jobs are put into a FIFO
- linked list and will not be touched until a client kicks them.
-
- @param integer $id The id of the job.
- @param integer $pri New priority to assign to the job.
- @return boolean
false on error,true on success.
*/
public function bury($id,$pri) {
$this->_write(sprintf('bury %d %d',$pri));
$status = $this->_read();
switch ($status) {
case 'BURIED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/**
- Allows a worker to request more time to work on a job.
-
- @param integer $id The id of the job.
- @return boolean
false on error,true on success.
*/
public function touch($id) {
$this->_write(sprintf('touch %d',$id));
$status = $this->_read();
switch ($status) {
case 'TOUCHED':
return true;
case 'NOT_TOUCHED':
default:
$this->_error($status);
return false;
}
}
/**
- Adds the named tube to the watch list for the current connection.
-
- @param string $tube Name of tube to watch.
- @return integer|boolean
false on error otherwise number of tubes in watch list.
*/
public function watch($tube) {
$this->_write(sprintf('watch %s',' ');
switch ($status) {
case 'WATCHING':
return (integer) strtok(' ');
default:
$this->_error($status);
return false;
}
}
/**
- Remove the named tube from the watch list.
-
- @param string $tube Name of tube to ignore.
- @return integer|boolean
false on error otherwise number of tubes in watch list.
*/
public function ignore($tube) {
$this->_write(sprintf('ignore %s',' ');
switch ($status) {
case 'WATCHING':
return (integer) strtok(' ');
case 'NOT_IGNORED':
default:
$this->_error($status);
return false;
}
}
/ Other Commands /
/**
- Inspect a job by its id.
-
- @param integer $id The id of the job.
- @return string|boolean
false on error otherwise the body of the job.
*/
public function peek($id) {
$this->_write(sprintf('peek %d',$id));
return $this->_peekRead();
}
/**
- Inspect the next ready job.
-
- @return string|boolean
false on error otherwise the body of the job.
*/
public function peekReady() {
$this->_write('peek-ready');
return $this->_peekRead();
}
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|