Esempio n. 1
0
 /**
  * Esegue il worker ad libitum
  *
  * @param string $tube
  * @return void
  */
 public function execute($tube)
 {
     $queue = new Pheanstalk($this->host);
     declare (ticks=1);
     $tube = !is_null($tube) ? QueueManager::resolveChannelName($tube) : null;
     $queue->watch($tube);
     pcntl_signal(SIGTERM, function ($signal) use($tube) {
         $this->shouldClose = true;
         if ((int) QueueManager::getTubeStats($tube, 'current-jobs-ready') === 0) {
             exit;
         }
     });
     while ($job = $queue->reserve()) {
         try {
             $this->log($job, "Starting Job...");
             $this->jobRunner->execute($job, $this->logger);
         } catch (\Exception $e) {
             $this->log($job, "Job Failed and Buried: " . $e->getMessage(), LoggerInterface::SEVERITY_ERROR);
             $queue->bury($job);
             continue;
         }
         $this->log($job, "Job Finished Succesfully");
         $queue->delete($job);
         $this->closeIfPossible();
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tube = $input->getArgument('tube');
     $resolvedTubeName = \Mosaicoon\QueueManager\QueueManager::resolveChannelName($tube);
     cli_set_process_title('JambonQueueListener-' . $resolvedTubeName);
     $worker = new Worker('127.0.0.1', new JobRunner(), new QMLogger($output));
     $this->printFiglet();
     $output->writeln("<info>In attesa di Job in coda sul canale {$resolvedTubeName}...</info>");
     $worker->execute($tube);
 }