GearmanWorkerListCommand.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Mmoreram\GearmanBundle\Command;
  3. use Symfony\Component\Console\Input\InputOption;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputDefinition;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  9. /**
  10. * Gearman Job List Command class
  11. *
  12. * @author Marc Morera <yuhu@mmoreram.com>
  13. */
  14. class GearmanWorkerListCommand extends ContainerAwareCommand
  15. {
  16. /**
  17. * Console Command configuration
  18. */
  19. protected function configure()
  20. {
  21. parent::configure();
  22. $this->setName('gearman:worker:list')
  23. ->setDescription('List all Gearman Workers and their Jobs');
  24. }
  25. /**
  26. * Executes the current command.
  27. *
  28. * @param InputInterface $input An InputInterface instance
  29. * @param OutputInterface $output An OutputInterface instance
  30. *
  31. * @return integer 0 if everything went fine, or an error code
  32. *
  33. * @throws \LogicException When this abstract class is not implemented
  34. */
  35. protected function execute(InputInterface $input, OutputInterface $output)
  36. {
  37. $workers = $this->getContainer()->get('gearman')->getWorkers();
  38. if (is_array($workers)) {
  39. $it = 1;
  40. foreach ($workers as $worker) {
  41. $output->writeln('<comment> @Worker: </comment><info>'.$worker['className'].'</info>');
  42. $output->writeln('<comment> callablename: </comment><info>'.$worker['callableName'].'</info>');
  43. $output->writeln('<comment> Jobs:</comment>');
  44. foreach ($worker['jobs'] as $job) {
  45. $output->writeln('<comment> - #'.$it++.'</comment>');
  46. $output->writeln('<comment> name: '.$job['methodName'].'</comment>');
  47. $output->writeln('<comment> callablename:</comment><info> '.$job['realCallableName'].'</info>');
  48. }
  49. $output->writeln('');
  50. }
  51. }
  52. }
  53. }