/**
  * setup
  */
 public function setUp()
 {
     $this->command = $this->getMockBuilder('Mmoreram\\GearmanBundle\\Command\\GearmanWorkerListCommand')->setMethods(null)->getMock();
     $this->input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputInterface')->disableOriginalConstructor()->setMethods(array())->getMock();
     $this->output = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')->disableOriginalConstructor()->setMethods(array())->getMock();
     $this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\KernelInterface')->disableOriginalConstructor()->setMethods(array())->getMock();
     $this->gearmanClient = $this->getMockBuilder('Mmoreram\\GearmanBundle\\Service\\GearmanClient')->disableOriginalConstructor()->setMethods(array('getWorkers'))->getMock();
     $this->gearmanClient->expects($this->any())->method('getWorkers')->will($this->returnValue(array(array('className' => '', 'callableName' => '', 'jobs' => array()))));
     $this->kernel->expects($this->any())->method('getEnvironment')->will($this->returnValue('dev'));
 }
 /**
  * Test quietness
  *
  * @dataProvider dataQuietness
  */
 public function testQuietness($quiet, $noInteraction, $confirmation, $countWriteln, $countDescriber, $countClient, $countExecute)
 {
     $this->input->expects($this->any())->method('getOption')->will($this->returnValueMap(array(array('quiet', $quiet), array('no-interaction', $noInteraction))));
     $this->questionHelper->expects($this->any())->method('ask')->will($this->returnValue($confirmation));
     $this->output->expects($countWriteln)->method('writeln');
     $this->gearmanDescriber->expects($countDescriber)->method('describeJob')->will($this->returnValue('olakase'));
     $this->gearmanClient->expects($countClient)->method('getJob')->will($this->returnValue(array()));
     $this->gearmanExecute->expects($countExecute)->method('executeJob');
     $this->command->setGearmanClient($this->gearmanClient)->setGearmanDescriber($this->gearmanDescriber)->setGearmanExecute($this->gearmanExecute)->setKernel($this->kernel)->run($this->input, $this->output);
 }
 /**
  * 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)
 {
     if ($input->getOption('quiet')) {
         return;
     }
     $workers = $this->gearmanClient->getWorkers();
     if (is_array($workers)) {
         $it = 1;
         foreach ($workers as $worker) {
             $output->writeln('<comment>@Worker:  </comment><info>' . $worker['className'] . '</info>');
             $output->writeln('<comment>callablename:  </comment><info>' . $worker['callableName'] . '</info>');
             $output->writeln('<comment>Jobs:</comment>');
             foreach ($worker['jobs'] as $job) {
                 $output->writeln('<comment>  - #' . $it++ . '</comment>');
                 $output->writeln('<comment>      name: ' . $job['methodName'] . '</comment>');
                 $output->writeln('<comment>      callablename:</comment><info> ' . $job['realCallableNameNoPrefix'] . '</info>');
                 if (false === is_null($job['jobPrefix'])) {
                     $output->writeln('<comment>      jobPrefix:</comment><info> ' . $job['jobPrefix'] . '</info>');
                 }
             }
         }
     }
 }
 /**
  * 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)
 {
     /**
      * @var DialogHelper $dialog
      */
     $dialog = $this->getHelperSet()->get('dialog');
     if (!$input->getOption('no-interaction') && !$dialog->askConfirmation($output, '<question>This will execute asked worker with all its jobs?</question>', 'y')) {
         return;
     }
     if (!$input->getOption('quiet')) {
         $output->writeln(sprintf('<info>[%s] loading...</info>', date('Y-m-d H:i:s')));
     }
     $worker = $input->getArgument('worker');
     $workerStructure = $this->gearmanClient->getWorker($worker);
     if (!$input->getOption('no-description') && !$input->getOption('quiet')) {
         $this->gearmanDescriber->describeWorker($output, $workerStructure, true);
     }
     if (!$input->getOption('quiet')) {
         $output->writeln(sprintf('<info>[%s] loaded. Ctrl+C to break</info>', date('Y-m-d H:i:s')));
     }
     $this->gearmanExecute->setOutput($output)->executeWorker($worker, array('iterations' => $input->getOption('iterations'), 'minimum_execution_time' => $input->getOption('minimum-execution-time'), 'timeout' => $input->getOption('timeout')));
 }
 /**
  * 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)
 {
     /**
      * @var DialogHelper $dialog
      */
     $dialog = $this->getHelperSet()->get('dialog');
     if (!$input->getOption('no-interaction') && !$dialog->askConfirmation($output, '<question>This will execute asked job?</question>', 'y')) {
         return;
     }
     if (!$input->getOption('quiet')) {
         $output->writeln(sprintf('<info>[%s] loading...</info>', date('Y-m-d H:i:s')));
     }
     $job = $input->getArgument('job');
     $jobStructure = $this->gearmanClient->getJob($job);
     if (!$input->getOption('quiet')) {
         $this->gearmanDescriber->describeJob($output, $jobStructure, true);
     }
     if (!$input->getOption('quiet')) {
         $output->writeln(sprintf('<info>[%s] loaded. Ctrl+C to break</info>', date('Y-m-d H:i:s')));
     }
     $this->gearmanExecute->setOutput($output)->executeJob($job);
 }
 /**
  * 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)
 {
     /**
      * @var QuestionHelper $question
      */
     $question = $this->getHelperSet()->get('question');
     if (!$input->getOption('no-interaction') && !$question->ask($input, $output, new ConfirmationQuestion('This will execute asked job?'))) {
         return;
     }
     if (!$input->getOption('quiet')) {
         $output->writeln(sprintf('<info>[%s] loading...</info>', date('Y-m-d H:i:s')));
     }
     $job = $input->getArgument('job');
     $jobStructure = $this->gearmanClient->getJob($job);
     if (!$input->getOption('no-description') && !$input->getOption('quiet')) {
         $this->gearmanDescriber->describeJob($output, $jobStructure, true);
     }
     if (!$input->getOption('quiet')) {
         $output->writeln(sprintf('<info>[%s] loaded. Ctrl+C to break</info>', date('Y-m-d H:i:s')));
     }
     $this->gearmanExecute->setOutput($output)->executeJob($job, array('iterations' => $input->getOption('iterations'), 'minimum_execution_time' => $input->getOption('minimum-execution-time'), 'timeout' => $input->getOption('timeout')));
 }
 /**
  * Given a GearmanClient, set timeout
  *
  * @param \GearmanClient $gearmanClient Object to include servers
  *
  * @return GearmanClient Returns self object
  */
 protected function assignTimeout(\GearmanClient $gearmanClient)
 {
     if ($this->timeout) {
         $gearmanClient->setTimeout($this->timeout);
     }
     return $this;
 }
 /**
  * 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)
 {
     $worker = $input->getArgument('worker');
     $worker = $this->gearmanClient->getWorker($worker);
     $this->gearmanDescriber->describeWorker($output, $worker);
 }
Example #9
0
 /**
  * Given a GearmanClient, set all included servers
  *
  * @param \GearmanClient $gearmanClient Object to include servers
  *
  * @return GearmanClient Returns self object
  */
 protected function assignServers(\GearmanClient $gearmanClient)
 {
     $servers = $this->defaultServers;
     if (!empty($this->servers)) {
         $servers = $this->servers;
     }
     /**
      * We include each server into gearman client
      */
     foreach ($servers as $server) {
         $gearmanClient->addServer($server['host'], $server['port']);
     }
     return $this;
 }
 /**
  * @param JobRequestInterface $job
  * @return mixed
  */
 public function addJob(JobRequestInterface $job)
 {
     $this->client->doBackgroundJob('IceJobBundleGearmanWorker~addDomainJob', $this->requestSerializer->serializeJobRequest($job));
 }
 /**
  * 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)
 {
     $job = $input->getArgument('job');
     $job = $this->gearmanClient->getJob($job);
     $this->gearmanDescriber->describeJob($output, $job);
 }