* @since 2013 */ namespace Mmoreram\GearmanBundle\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; /** * Gearman Worker Execute Command class * * @author Marc Morera */ class GearmanWorkerExecuteCommand extends ContainerAwareCommand { /** * Console Command configuration */ protected function configure() { parent::configure(); $this ->setName('gearman:worker:execute') ->setDescription('Execute one worker with all contained Jobs') ->addArgument('worker', InputArgument::REQUIRED, 'work to execute') ->addOption('no-description', null, InputOption::VALUE_NONE, 'Don\'t print worker description'); } /** * Executes the current command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return integer 0 if everything went fine, or an error code * * @throws \LogicException When this abstract class is not implemented */ protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); if (!$input->getOption('no-interaction') && !$dialog->askConfirmation($output, 'This will execute asked worker with all its jobs?', 'y')) { return; } $output->writeln(sprintf('[%s] loading...', date('Y-m-d H:i:s'))); $worker = $input->getArgument('worker'); $workerStruct = $this->getContainer()->get('gearman')->getWorker($worker); if (!$input->getOption('no-description')) { $this->getContainer()->get('gearman.describer')->describeWorker($output, $workerStruct, true); } $output->writeln(sprintf('[%s] loaded. Ctrl+C to break', date('Y-m-d H:i:s'))); $this->getContainer()->get('gearman.execute')->executeWorker($worker); } }