Exemplo 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);
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $action = $input->getArgument('action');
     $params = @json_decode($input->getOption('params'), true);
     $times = (int) $input->getOption('times');
     $tube = $input->getOption('tube');
     for ($i = 0; $i < $times; $i++) {
         $this->pushInQueue($action, $params, $tube);
     }
     $output->writeln("<info>Pushati {$times} {$action}</info>");
     if ($input->getOption('keep-alive')) {
         while ($count = QueueManager::getTubeStats($tube, 'current-jobs-ready')) {
             //$output->writeln("\033 {$count} processi in coda", OutputInterface::OUTPUT_RAW);
             $string = "{$count} processi in coda";
             $back = strlen($string);
             echo "[{$back}D" . $string;
             //$output->writeln("\033[{$back}D" . $string, OutputInterface::OUTPUT_RAW);
         }
         echo "\n";
         $output->writeln("<info>Finito</info>");
     }
 }
Exemplo n.º 4
0
 /**
  * Scrive i log
  *
  * @param string $command
  * @param array $params (optional)
  * @param string $tube (optional)
  * @return bool
  */
 public function pushInQueue($command, array $params = null, $tube = null)
 {
     return QueueManager::push(Messenger::pack($command, $params), $tube);
 }