예제 #1
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $actions = $input->getArgument('action');
     if (empty($actions)) {
         $actions = array_keys($this->manager->getExecutors());
     }
     $states = $input->getOption('state');
     $pheanstalk = $this->manager->getPheanstalk();
     foreach ($actions as $action) {
         try {
             $stats = $pheanstalk->statsTube($action);
             $amount = 0;
             foreach ($states as $state) {
                 $amount += $stats['current-jobs-' . $state];
             }
             $output->writeln(sprintf('Clearing <info>%d %s jobs</info> with <info>%s</info> status', $amount, $action, implode(', ', $states)));
             $this->manager->clear($action, $states);
             $output->writeln(['<info>Done!</info>', '']);
         } catch (ServerException $e) {
             if (false === strpos($e->getMessage(), 'NOT_FOUND')) {
                 throw $e;
             }
         }
     }
 }
 /**
  * @param OutputInterface $output
  * @param string          $action
  * @param int             $limit
  */
 protected function inspect(OutputInterface $output, $action, $limit = null)
 {
     $output->writeln(sprintf('Inspecting jobs for the <info>%s</info> action', $action));
     $this->manager->watchOnly([$action]);
     $jobs = [];
     while ($job = $this->manager->get(1)) {
         $output->writeln(sprintf('<info>%d</info>: <comment>%s</comment>', $job->getId(), $job->getData()));
         $jobs[] = $job;
         if (null !== $limit && sizeof($jobs) >= $limit) {
             break;
         }
     }
     $output->writeln('Releasing the jobs back to the queue, <error>don\'t cancel this action!</error>');
     foreach ($jobs as $job) {
         $stats = $this->manager->getJobStats($job);
         $this->manager->getPheanstalk()->release($job, $stats['pri']);
     }
 }
 public function testGetPheanstalk()
 {
     $this->assertSame($this->pheanstalk, $this->manager->getPheanstalk());
 }