/** * Valid option is: * - timeout: by default, when we ask for a job, it will block until a job is found (possibly forever if * new jobs never come). If you set a timeout (in seconds), it will return after the timeout is * expired, even if no jobs were found * * {@inheritDoc} */ public function pop(array $options = array()) { $job = $this->pheanstalk->reserveFromTube($this->getTubeName(), isset($options['timeout']) ? $options['timeout'] : null); if (!$job instanceof PheanstalkJob) { return null; } return $this->unserializeJob($job->getData(), array('__id__' => $job->getId())); }
/** * Wait for a message in the queue and save the message to a safety queue * * TODO: Idea for implementing a TTR (time to run) with monitoring of safety queue. E.g. * use different queue names with encoded times? With brpoplpush we cannot modify the * queued item on transfer to the safety queue and we cannot update a timestamp to mark * the run start time in the message, so separate keys should be used for this. * * @param integer $timeout in seconds * @return Message */ public function waitAndReserve($timeout = NULL) { if ($timeout === NULL) { $timeout = $this->defaultTimeout; } $pheanstalkJob = $this->client->reserveFromTube($this->name, $timeout); if ($pheanstalkJob === NULL || $pheanstalkJob === FALSE) { return NULL; } $message = $this->decodeMessage($pheanstalkJob->getData()); $message->setIdentifier($pheanstalkJob->getId()); return $message; }
public function pop($queue) { $job = $this->beanstalkd->reserveFromTube($queue, $this->timeout); return ['id' => $job->getId(), 'queue' => $queue, 'body' => $job->getData()]; }
public function pop($queue) { $job = $this->beanstalkd->reserveFromTube($queue); return ['id' => $job['id'], 'queue' => $queue, 'body' => $job['data']]; }
public function clearQueue($queue = 'default') { while ($job = $this->queue->reserveFromTube($queue, 0)) { $this->queue->delete($job); } }
/** * @inheritdoc */ public function waitAndReserve($timeout = null) { if ($timeout === null) { $timeout = $this->defaultTimeout; } $pheanstalkJob = $this->client->reserveFromTube($this->name, $timeout); if ($pheanstalkJob === null || $pheanstalkJob === false) { return null; } $pheanstalkJobStats = $this->client->statsJob($pheanstalkJob); $numberOfReleases = isset($pheanstalkJobStats['reserves']) && $pheanstalkJobStats['reserves'] > 0 ? (int) $pheanstalkJobStats['reserves'] - 1 : 0; return new Message((string) $pheanstalkJob->getId(), json_decode($pheanstalkJob->getData(), true), $numberOfReleases); }