123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- /**
- * Gearman Bundle for Symfony2
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * Feel free to edit as you please, and have fun.
- *
- * @author Marc Morera <yuhu@mmoreram.com>
- */
- namespace Mmoreram\GearmanBundle\Service;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\HttpKernel\KernelInterface;
- /**
- * Implementation of GearmanDescriber
- *
- * @since 2.3.1
- */
- class GearmanDescriber
- {
- /**
- * @var KernelInterface
- *
- * Kernel
- */
- private $kernel;
- /**
- * Construct method
- *
- * @param KernelInterface $kernel Kernel
- */
- public function __construct(KernelInterface $kernel)
- {
- $this->kernel = $kernel;
- }
- /**
- * Describe Job.
- *
- * Given a output object and a Job, dscribe it.
- *
- * @param OutputInterface $output Output object
- * @param array $worker Worker array with Job to describe
- */
- public function describeJob(OutputInterface $output, array $worker)
- {
- /**
- * Commandline
- */
- $script = $this->kernel->getRootDir() . '/console gearman:job:execute';
- /**
- * A job descriptions contains its worker description
- */
- $this->describeWorker($output, $worker);
- $job = $worker['job'];
- $output->writeln('<info>@job\methodName : ' . $job['methodName'] . '</info>');
- $output->writeln('<info>@job\callableName : ' . $job['realCallableName'] . '</info>');
- if ($job['jobPrefix']) {
- $output->writeln('<info>@job\jobPrefix : ' . $job['jobPrefix'] . '</info>');
- }
- /**
- * Also a complete and clean execution path is given , for supervisord
- */
- $output->writeln('<info>@job\supervisord : </info><comment>/usr/bin/php ' . $script.' ' . $job['realCallableName'] . ' --no-interaction</comment>');
- $output->writeln('<info>@job\iterations : ' . $job['iterations'] . '</info>');
- $output->writeln('<info>@job\defaultMethod : ' . $job['defaultMethod'] . '</info>');
- /**
- * Printed every server is defined for current job
- */
- $output->writeln('');
- $output->writeln('<info>@job\servers :</info>');
- $output->writeln('');
- foreach ($job['servers'] as $name => $server) {
- $output->writeln('<comment> ' . $name . ' - ' . $server['host'] . ':' . $server['port'] . '</comment>');
- }
- /**
- * Description
- */
- $output->writeln('');
- $output->writeln('<info>@job\description :</info>');
- $output->writeln('');
- $output->writeln('<comment> #' . $job['description'] . '</comment>');
- $output->writeln('');
- }
- /**
- * Describe Worker.
- *
- * Given a output object and a Worker, dscribe it.
- *
- * @param OutputInterface $output Output object
- * @param array $worker Worker array with Job to describe
- * @param Boolean $tinyJobDescription If true also print job list
- */
- public function describeWorker(OutputInterface $output, array $worker, $tinyJobDescription = false)
- {
- /**
- * Commandline
- */
- $script = $this->kernel->getRootDir() . '/console gearman:worker:execute';
- $output->writeln('');
- $output->writeln('<info>@Worker\className : ' . $worker['className'] . '</info>');
- $output->writeln('<info>@Worker\fileName : ' . $worker['fileName'] . '</info>');
- $output->writeln('<info>@Worker\nameSpace : ' . $worker['namespace'] . '</info>');
- $output->writeln('<info>@Worker\callableName: ' . $worker['callableName'] . '</info>');
- /**
- * Also a complete and clean execution path is given , for supervisord
- */
- $output->writeln('<info>@Worker\supervisord : </info><comment>/usr/bin/php ' . $script.' ' . $worker['callableName'] . ' --no-interaction</comment>');
- /**
- * Service value is only explained if defined. Not mandatory
- */
- if (null !== $worker['service']) {
- $output->writeln('<info>@Worker\service : ' . $worker['service'] . '</info>');
- }
- $output->writeln('<info>@worker\iterations : ' . $worker['iterations'] . '</info>');
- $output->writeln('<info>@Worker\#jobs : ' . count($worker['jobs']) . '</info>');
- if ($tinyJobDescription) {
- $output->writeln('<info>@Worker\jobs</info>');
- $output->writeln('');
- foreach ($worker['jobs'] as $job) {
- if ($job['jobPrefix']) {
- $output->writeln('<comment> # ' . $job['realCallableNameNoPrefix'] . ' with jobPrefix: ' . $job['jobPrefix'] . '</comment>');
- } else {
- $output->writeln('<comment> # ' . $job['realCallableNameNoPrefix'] . ' </comment>');
- }
- }
- }
- /**
- * Printed every server is defined for current job
- */
- $output->writeln('');
- $output->writeln('<info>@worker\servers :</info>');
- $output->writeln('');
- foreach ($worker['servers'] as $name => $server) {
- $output->writeln('<comment> #' . $name . ' - ' . $server['host'] . ':' . $server['port'] . '</comment>');
- }
- /**
- * Description
- */
- $output->writeln('');
- $output->writeln('<info>@Worker\description :</info>');
- $output->writeln('');
- $output->writeln('<comment> ' . $worker['description'] . '</comment>');
- $output->writeln('');
- }
- }
|