GearmanWorkerDescribeCommand.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * Feel free to edit as you please, and have fun.
  9. *
  10. * @author Marc Morera <yuhu@mmoreram.com>
  11. */
  12. namespace Mmoreram\GearmanBundle\Command;
  13. use Symfony\Component\Console\Input\InputArgument;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. use Mmoreram\GearmanBundle\Command\Abstracts\AbstractGearmanCommand;
  17. use Mmoreram\GearmanBundle\Service\GearmanClient;
  18. use Mmoreram\GearmanBundle\Service\GearmanDescriber;
  19. /**
  20. * Gearman Job Describe Command class
  21. *
  22. * @since 2.3.1
  23. */
  24. class GearmanWorkerDescribeCommand extends AbstractGearmanCommand
  25. {
  26. /**
  27. * @var GearmanClient
  28. *
  29. * Gearman client
  30. */
  31. protected $gearmanClient;
  32. /**
  33. * @var GearmanDescriber
  34. *
  35. * GearmanDescriber
  36. */
  37. protected $gearmanDescriber;
  38. /**
  39. * Set gearman client
  40. *
  41. * @param GearmanClient $gearmanClient Gearman client
  42. *
  43. * @return GearmanWorkerDescribeCommand self Object
  44. */
  45. public function setGearmanClient(GearmanClient $gearmanClient)
  46. {
  47. $this->gearmanClient = $gearmanClient;
  48. return $this;
  49. }
  50. /**
  51. * set Gearman describer
  52. *
  53. * @param GearmanDescriber $gearmanDescriber GearmanDescriber
  54. *
  55. * @return GearmanWorkerDescribeCommand self Object
  56. */
  57. public function setGearmanDescriber(GearmanDescriber $gearmanDescriber)
  58. {
  59. $this->gearmanDescriber = $gearmanDescriber;
  60. return $this;
  61. }
  62. /**
  63. * Console Command configuration
  64. */
  65. protected function configure()
  66. {
  67. parent::configure();
  68. $this
  69. ->setName('gearman:worker:describe')
  70. ->setDescription('Describe given worker')
  71. ->addArgument(
  72. 'worker',
  73. InputArgument::REQUIRED,
  74. 'worker to describe'
  75. );
  76. }
  77. /**
  78. * Executes the current command.
  79. *
  80. * @param InputInterface $input An InputInterface instance
  81. * @param OutputInterface $output An OutputInterface instance
  82. *
  83. * @return integer 0 if everything went fine, or an error code
  84. *
  85. * @throws \LogicException When this abstract class is not implemented
  86. */
  87. protected function execute(InputInterface $input, OutputInterface $output)
  88. {
  89. $worker = $input->getArgument('worker');
  90. $worker = $this
  91. ->gearmanClient
  92. ->getWorker($worker);
  93. $this
  94. ->gearmanDescriber
  95. ->describeWorker(
  96. $output,
  97. $worker
  98. );
  99. }
  100. }