GearmanJobDescribeCommand.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Mmoreramerino\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. class GearmanJobDescribeCommand extends ContainerAwareCommand
  10. {
  11. /**
  12. * Console Command configuration
  13. */
  14. protected function configure()
  15. {
  16. parent::configure();
  17. $this->setName('gearman:job:describe')
  18. ->setDescription('Describe given job')
  19. ->addArgument('job', InputArgument::REQUIRED, 'job to execute')
  20. ;
  21. }
  22. /**
  23. * Executes the current command.
  24. *
  25. * @param InputInterface $input An InputInterface instance
  26. * @param OutputInterface $output An OutputInterface instance
  27. *
  28. * @return integer 0 if everything went fine, or an error code
  29. *
  30. * @throws \LogicException When this abstract class is not implemented
  31. */
  32. protected function execute(InputInterface $input, OutputInterface $output)
  33. {
  34. $job = $input->getArgument('job');
  35. $worker = $this->getContainer()->get('gearman')->getWorker($job);
  36. $output->writeln('');
  37. $output->writeln('<info> @Worker\className : '.$worker['className'].'</info>');
  38. $output->writeln('<info> @Worker\fileName : '.$worker['fileName'].'</info>');
  39. $output->writeln('<info> @Worker\namespace : '.$worker['namespace'].'</info>');
  40. $output->writeln('<info> @Worker-jobsnumber : '.count($worker['jobs']).'</info>');
  41. $output->writeln('<info> @Worker\description :</info>');
  42. $output->writeln('');
  43. $output->writeln('<comment> '.$worker['description'].'</comment>');
  44. $output->writeln('');
  45. $job = $worker['job'];
  46. $output->writeln('<info> @job\methodName : '.$job['methodName'].'</info>');
  47. $output->writeln('<info> @job\callableName : '.$job['realCallableName'].'</info>');
  48. $output->writeln('<info> @job\iterations : '.$job['iter'].'</info>');
  49. $output->writeln('<info> @job\servers :</info>');
  50. $output->writeln('');
  51. foreach ($job['servers'] as $server) {
  52. $output->writeln('<comment> '.$server.'</comment>');
  53. }
  54. $output->writeln('');
  55. $output->writeln('<info> @job\description :</info>');
  56. $output->writeln('');
  57. $output->writeln('<comment> '.$job['description'].'</comment>');
  58. $output->writeln('');
  59. }
  60. }