*/
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('@job\methodName : ' . $job['methodName'] . '');
$output->writeln('@job\callableName : ' . $job['realCallableName'] . '');
if ($job['jobPrefix']) {
$output->writeln('@job\jobPrefix : ' . $job['jobPrefix'] . '');
}
/**
* Also a complete and clean execution path is given , for supervisord
*/
$output->writeln('@job\supervisord : /usr/bin/php ' . $script.' ' . $job['realCallableName'] . ' --no-interaction');
$output->writeln('@job\iterations : ' . $job['iterations'] . '');
$output->writeln('@job\defaultMethod : ' . $job['defaultMethod'] . '');
/**
* Printed every server is defined for current job
*/
$output->writeln('');
$output->writeln('@job\servers :');
$output->writeln('');
foreach ($job['servers'] as $name => $server) {
$output->writeln(' ' . $name . ' - ' . $server['host'] . ':' . $server['port'] . '');
}
/**
* Description
*/
$output->writeln('');
$output->writeln('@job\description :');
$output->writeln('');
$output->writeln(' #' . $job['description'] . '');
$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('@Worker\className : ' . $worker['className'] . '');
$output->writeln('@Worker\fileName : ' . $worker['fileName'] . '');
$output->writeln('@Worker\nameSpace : ' . $worker['namespace'] . '');
$output->writeln('@Worker\callableName: ' . $worker['callableName'] . '');
/**
* Also a complete and clean execution path is given , for supervisord
*/
$output->writeln('@Worker\supervisord : /usr/bin/php ' . $script.' ' . $worker['callableName'] . ' --no-interaction');
/**
* Service value is only explained if defined. Not mandatory
*/
if (null !== $worker['service']) {
$output->writeln('@Worker\service : ' . $worker['service'] . '');
}
$output->writeln('@worker\iterations : ' . $worker['iterations'] . '');
$output->writeln('@Worker\#jobs : ' . count($worker['jobs']) . '');
if ($tinyJobDescription) {
$output->writeln('@Worker\jobs');
$output->writeln('');
foreach ($worker['jobs'] as $job) {
if ($job['jobPrefix']) {
$output->writeln(' # ' . $job['realCallableNameNoPrefix'] . ' with jobPrefix: ' . $job['jobPrefix'] . '');
} else {
$output->writeln(' # ' . $job['realCallableNameNoPrefix'] . ' ');
}
}
}
/**
* Printed every server is defined for current job
*/
$output->writeln('');
$output->writeln('@worker\servers :');
$output->writeln('');
foreach ($worker['servers'] as $name => $server) {
$output->writeln(' #' . $name . ' - ' . $server['host'] . ':' . $server['port'] . '');
}
/**
* Description
*/
$output->writeln('');
$output->writeln('@Worker\description :');
$output->writeln('');
$output->writeln(' ' . $worker['description'] . '');
$output->writeln('');
}
}