GearmanJobDescribeCommand.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 GearmanJobDescribeCommand 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 GearmanJobDescribeCommand 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 GearmanJobDescribeCommand 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. $this
  68. ->setName('gearman:job:describe')
  69. ->setDescription('Describe given job')
  70. ->addArgument(
  71. 'job',
  72. InputArgument::REQUIRED,
  73. 'job to describe'
  74. );
  75. }
  76. /**
  77. * Executes the current command.
  78. *
  79. * @param InputInterface $input An InputInterface instance
  80. * @param OutputInterface $output An OutputInterface instance
  81. *
  82. * @return integer 0 if everything went fine, or an error code
  83. *
  84. * @throws \LogicException When this abstract class is not implemented
  85. */
  86. protected function execute(InputInterface $input, OutputInterface $output)
  87. {
  88. $job = $input->getArgument('job');
  89. $job = $this->gearmanClient->getJob($job);
  90. $this
  91. ->gearmanDescriber
  92. ->describeJob($output, $job);
  93. }
  94. }