Ejemplo n.º 1
0
 public function enqueue(Job $job)
 {
     if (!$this->pheanstalk) {
         throw new RuntimeException('The daemon is not connected.');
     }
     if (!$job->getTube()) {
         throw new RuntimeException('No tube provided so cannot add job');
     }
     $data = json_encode(['worker' => $job->getWorker(), 'params' => $job->getParams()]);
     $this->pheanstalk->useTube($job->getTube())->put($data, $job->getPriority(), $job->getDelay(), $job->getTimeToRun());
 }
Ejemplo n.º 2
0
 /**
  * Puts a job into a 'buried' state, revived only by 'kick' command.
  *
  * @param string $action
  * @param int    $max
  *
  * @return int The number of kicked jobs
  */
 public function kick($action, $max)
 {
     $this->pheanstalk->useTube($action);
     $kicked = $this->pheanstalk->kick($max);
     $this->logger->debug(sprintf('Kicked %d "%s" jobs back onto the ready queue', $kicked, $action));
     return $kicked;
 }
 /**
  * {@inheritDoc}
  */
 public function useTube($tube)
 {
     if ($this->dispatcher) {
         $this->dispatcher->dispatch(CommandEvent::USE_TUBE, new CommandEvent($this, ['tube' => $tube]));
     }
     $this->pheanstalk->useTube($tube);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Initializes the queue object
  *
  * @param \Pheanstalk\PheanstalkInterface $client Client object
  * @param string $queue Message queue name
  * @throws \Aimeos\MW\MQueue\Exception
  */
 public function __construct(\Pheanstalk\PheanstalkInterface $client, $queue, $timeout = null)
 {
     try {
         $client->useTube($queue)->watch($queue);
     } catch (\Exception $e) {
         throw new \Aimeos\MW\MQueue\Exception($e->getMessage());
     }
     $this->client = $client;
     $this->queue = $queue;
     $this->timeout = $timeout;
 }
Ejemplo n.º 5
0
 /**
  * Delete given job and create new job with old or passed params
  *
  * @param int $jobId
  * @param int $priority
  * @param int $delay
  */
 public function reschedule($jobId, $priority = NULL, $delay = NULL)
 {
     /** @var Job $job */
     $job = $this->pheanstalk->peek($jobId);
     $jobStats = $this->pheanstalk->statsJob($job);
     $this->pheanstalk->useTube($this->tube);
     $priority = NULL === $priority ? $jobStats['pri'] : $priority;
     $delay = NULL === $delay ? $jobStats['delay'] : $delay;
     $newJobId = $this->pheanstalk->put($job->getData(), $priority, $delay, $jobStats['ttr']);
     $this->pheanstalk->delete($job);
     $context = ['job_id' => $newJobId, 'old_job_id' => $jobId, 'text' => $job->getData(), 'priority' => $priority, 'delay' => $delay];
     $this->logger->info(sprintf('Reschedule job (%d => %d): %s', $jobId, $newJobId, $job->getData()), $context);
 }
Ejemplo n.º 6
0
 public function addJob($queueName, JobInterface $job)
 {
     $this->pheanstalk->useTube($queueName)->put($this->serializer->serialize($job));
 }