GearmanWorkerListCommand.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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->setName('gearman:worker:list')
  26. ->setDescription('List all Gearman Workers and their Jobs');
  27. }
  28. /**
  29. * Executes the current command.
  30. *
  31. * @param InputInterface $input An InputInterface instance
  32. * @param OutputInterface $output An OutputInterface instance
  33. *
  34. * @return integer 0 if everything went fine, or an error code
  35. *
  36. * @throws \LogicException When this abstract class is not implemented
  37. */
  38. protected function execute(InputInterface $input, OutputInterface $output)
  39. {
  40. $workers = $this->getContainer()->get('gearman')->getWorkers();
  41. if (is_array($workers)) {
  42. $it = 1;
  43. foreach ($workers as $worker) {
  44. $output->writeln('<comment> @Worker: </comment><info>'.$worker['className'].'</info>');
  45. $output->writeln('<comment> callablename: </comment><info>'.$worker['callableName'].'</info>');
  46. $output->writeln('<comment> Jobs:</comment>');
  47. foreach ($worker['jobs'] as $job) {
  48. $output->writeln('<comment> - #'.$it++.'</comment>');
  49. $output->writeln('<comment> name: '.$job['methodName'].'</comment>');
  50. $output->writeln('<comment> callablename:</comment><info> '.$job['realCallableNameNoPrefix'].'</info>');
  51. if (false === is_null($job['jobPrefix'])) {
  52. $output->writeln('<comment> job prefix:</comment><info> '.$job['jobPrefix'].'</info>');
  53. }
  54. }
  55. $output->writeln('');
  56. }
  57. }
  58. }
  59. }