GearmanWorkerListCommand.php 2.3 KB

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