示例#1
0
 protected function initCron()
 {
     if ($this->cron == null) {
         $this->cron = new Cron();
     }
     $this->cron->setResolver($this->getResolver());
     $this->cron->setExecutor($this->getExecutor());
 }
示例#2
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return CronService
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get(Config::class);
     $resolver = new ArrayResolver($config->getPhpPath(), $config->getScriptPath());
     $resolver->buildFromConfig($config->getJobs());
     $cron = new Cron();
     $cron->setResolver($resolver);
     $cron->setExecutor(new Executor());
     return new CronService($config->getTimeout(), $cron);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $cron = new Cron();
     $cron->setExecutor($this->getContainer()->get('cron.executor'));
     if ($input->getArgument('job')) {
         $resolver = $this->getJobResolver($input->getArgument('job'), $input->hasOption('force'));
     } else {
         $resolver = $this->getContainer()->get('cron.resolver');
     }
     $cron->setResolver($resolver);
     $time = microtime(true);
     $dbReport = $cron->run();
     while ($cron->isRunning()) {
     }
     $output->writeln('time: ' . (microtime(true) - $time));
     $manager = $this->getContainer()->get('cron.manager');
     $manager->saveReports($dbReport->getReports());
 }