GearmanJobExecuteCommand.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Mmoreramerino\GearmanBundle\Command;
  3. use Symfony\Component\Console\Input\InputOption;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputDefinition;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  9. class GearmanJobExecuteCommand extends ContainerAwareCommand
  10. {
  11. /**
  12. * Console Command configuration
  13. */
  14. protected function configure()
  15. {
  16. parent::configure();
  17. $this->setName('gearman:job:execute')
  18. ->setDescription('Execute one job of worker')
  19. ->addArgument('job', InputArgument::REQUIRED, 'Job to execute')
  20. ;
  21. }
  22. /**
  23. * Executes the current command.
  24. *
  25. * @param InputInterface $input An InputInterface instance
  26. * @param OutputInterface $output An OutputInterface instance
  27. *
  28. * @return integer 0 if everything went fine, or an error code
  29. *
  30. * @throws \LogicException When this abstract class is not implemented
  31. */
  32. protected function execute(InputInterface $input, OutputInterface $output)
  33. {
  34. $dialog = $this->getHelperSet()->get('dialog');
  35. if (!$input->getOption('no-interaction') && !$dialog->askConfirmation($output, '<question>This will execute asked worker?</question>', 'y')) {
  36. return;
  37. }
  38. $job = $input->getArgument('job');
  39. $this->getContainer()->get('gearman.execute.job')->executeJob($job);
  40. }
  41. }