/** * 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) { $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>"); } }