GearmanDescriber.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace Mmoreram\GearmanBundle\Service;
  3. use Symfony\Component\Console\Output\OutputInterface;
  4. use Symfony\Component\HttpKernel\Kernel;
  5. /**
  6. * Implementation of GearmanDescriber
  7. *
  8. * @author Marc Morera <yuhu@mmoreram.com>
  9. */
  10. class GearmanDescriber
  11. {
  12. /**
  13. * @var Kernel
  14. *
  15. * Kernel
  16. */
  17. private $kernel;
  18. /**
  19. * Construct method
  20. *
  21. * @param Kernel $kernel Kernel
  22. */
  23. public function __construct(Kernel $kernel)
  24. {
  25. $this->kernel = $kernel;
  26. }
  27. /**
  28. * Describe Job.
  29. *
  30. * Given a output object and a Job, dscribe it.
  31. *
  32. * @param OutputInterface $output Output object
  33. * @param array $worker Worker array with Job to describe
  34. */
  35. public function describeJob(OutputInterface $output, array $worker)
  36. {
  37. $script = $this->kernel->getRootDir() . '/console gearman:job:execute';
  38. $this->describeWorker($output, $worker);
  39. $job = $worker['job'];
  40. $output->writeln('<info> @job\methodName : ' . $job['methodName'] . '</info>');
  41. $output->writeln('<info> @job\callableName : ' . $job['realCallableName'] . '</info>');
  42. $output->writeln('<info> @job\supervisord : </info><comment>/usr/bin/php ' . $script.' ' . $job['realCallableName'] . ' --no-interaction</comment>');
  43. $output->writeln('<info> @job\iterations : ' . $job['iterations'] . '</info>');
  44. $output->writeln('<info> @job\defaultMethod : ' . $job['defaultMethod'] . '</info>');
  45. $output->writeln('<info> @job\servers :</info>');
  46. $output->writeln('');
  47. foreach ($job['servers'] as $name => $server) {
  48. $output->writeln('<comment> ' . $name . ' - ' . $server['host'] . ':' . $server['port'] . '</comment>');
  49. }
  50. $output->writeln('');
  51. $output->writeln('<info> @job\description :</info>');
  52. $output->writeln('');
  53. $output->writeln('<comment> #' . $job['description'] . '</comment>');
  54. $output->writeln('');
  55. }
  56. /**
  57. * Describe Worker.
  58. *
  59. * Given a output object and a Worker, dscribe it.
  60. *
  61. * @param OutputInterface $output Output object
  62. * @param array $worker Worker array with Job to describe
  63. * @param Boolean $tinyJobDescription If true also print job list
  64. */
  65. public function describeWorker(OutputInterface $output, array $worker, $tinyJobDescription = false)
  66. {
  67. $script = $this->kernel->getRootDir() . '/console gearman:worker:execute';
  68. $output->writeln('');
  69. $output->writeln('<info> @Worker\className : ' . $worker['className'] . '</info>');
  70. $output->writeln('<info> @Worker\fileName : ' . $worker['fileName'] . '</info>');
  71. $output->writeln('<info> @Worker\nameSpace : ' . $worker['namespace'] . '</info>');
  72. $output->writeln('<info> @Worker\callableName: ' . $worker['callableName'] . '</info>');
  73. $output->writeln('<info> @Worker\supervisord : </info><comment>/usr/bin/php ' . $script.' ' . $worker['callableName'] . ' --no-interaction</comment>');
  74. if (null !== $worker['service']) {
  75. $output->writeln('<info> @Worker\service : ' . $worker['service'] . '</info>');
  76. }
  77. $output->writeln('<info> @worker\iterations : ' . $worker['iterations'] . '</info>');
  78. $output->writeln('<info> @Worker\#jobs : '.count($worker['jobs']).'</info>');
  79. if ($tinyJobDescription) {
  80. $output->writeln('<info> @Worker\jobs</info>');
  81. $output->writeln('');
  82. foreach ($worker['jobs'] as $job) {
  83. $output->writeln('<comment> # ' . $job['realCallableName'] . '</comment>');
  84. }
  85. }
  86. $output->writeln('');
  87. $output->writeln('<info> @worker\servers :</info>');
  88. $output->writeln('');
  89. foreach ($worker['servers'] as $name => $server) {
  90. $output->writeln('<comment> #' . $name . ' - ' . $server['host'] . ':' . $server['port'] . '</comment>');
  91. }
  92. $output->writeln('');
  93. $output->writeln('<info> @Worker\description :</info>');
  94. $output->writeln('');
  95. $output->writeln('<comment> ' . $worker['description'] . '</comment>');
  96. $output->writeln('');
  97. }
  98. }