Пример #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;
             }
         }
     }
 }
 public function testGetSetExecutors()
 {
     $executor = new Executor();
     $name = $executor->getName();
     $this->assertFalse($this->manager->hasExecutor($name));
     $this->manager->addExecutor($executor);
     $this->assertTrue($this->manager->hasExecutor($name));
     $this->assertSame($executor, $this->manager->getExecutor($name));
     $this->assertEquals([$name => $executor], $this->manager->getExecutors());
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $actions = $input->getArgument('action');
     if (empty($actions)) {
         $actions = array_keys($this->manager->getExecutors());
     }
     $empty = $input->getOption('empty');
     $refresh = $input->getOption('refresh');
     if ($input->isInteractive()) {
         $output->writeln(['', sprintf('This list refreshes every <comment>%d</comment> second(s), type CTRL-C to exit', $refresh), '']);
         while (true) {
             $this->render($output, $actions, $empty);
             sleep($refresh);
         }
     } else {
         $this->render($output, $actions, $input->getOption('empty'));
     }
     return 0;
 }
Пример #4
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');
     foreach ($actions as $action) {
         $output->writeln(sprintf('Action: <info>%s</info>', $action));
         $table = new Table($output);
         $table->setHeaders(['state', 'id', 'data']);
         foreach ($states as $state) {
             $job = $this->manager->peek($action, $state);
             if (is_null($job)) {
                 $table->addRow([$state, '-', '-']);
             } else {
                 $table->addRow([$state, $job->getId(), $job->getData()]);
             }
         }
         $table->render();
         $output->writeln('');
     }
 }
Пример #5
0
 /**
  * @param string[] $include
  * @param string[] $exclude
  */
 protected function watchActions(array $include = [], array $exclude = [])
 {
     $actions = array_keys($this->manager->getExecutors());
     if (empty($include)) {
         $include = $actions;
     }
     if (!empty($diff = array_diff($include, $actions))) {
         throw new \InvalidArgumentException(sprintf('Action(s) "%s" are not defined by QueueManager', implode(', ', $diff)));
     }
     if (!empty($diff = array_diff($exclude, $actions))) {
         throw new \InvalidArgumentException(sprintf('Filter(s) "%s" are not defined by QueueManager', implode(', ', $diff)));
     }
     $include = array_diff($include, $exclude);
     if (empty($include)) {
         throw new \InvalidArgumentException('No actions specified to run');
     }
     // watch only these actions
     $this->manager->watchOnly($include);
 }