GearmanJobDescribeCommand.php 2.7 KB

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