Example #1
0
 /**
  * Transform a CronJon into a ShellJob.
  *
  * @param  CronJob  $dbJob
  * @return ShellJob
  */
 protected function createJob(CronJob $dbJob)
 {
     $job = new ShellJob();
     $job->setCommand($this->commandBuilder->build($dbJob->getCommand()), $this->rootDir);
     $job->setSchedule(new CrontabSchedule($dbJob->getSchedule()));
     $job->raw = $dbJob;
     return $job;
 }
Example #2
0
 protected function addJobs()
 {
     foreach ($this->configuration->getJobs() as $jobArray) {
         $job = new ShellJob();
         $job->setCommand($this->assembleShellJobString($jobArray['command']));
         $job->setSchedule(new CrontabSchedule($jobArray['schedule']));
         $this->getResolver()->addJob($job);
     }
 }
 /**
  * @expectedException \BitWeb\CronModule\Exception\TimeoutException
  */
 public function testTimeOut()
 {
     $job = new ShellJob();
     $job->setCommand('index.php application cron mail');
     $executorMock = $this->getMock(Executor::class);
     $executorMock->expects($this->any())->method('isRunning')->will($this->returnValue(true));
     $executorMock->expects($this->any())->method('getRunningJobs')->will($this->returnValue([$job]));
     $service = new CronService($this->configuration);
     $service->setExecutor($executorMock);
     $service->run();
     sleep(3);
 }
 /**
  * @param  string                    $jobName
  * @param  bool                      $force
  * @return ArrayResolver
  * @throws \InvalidArgumentException
  */
 protected function getJobResolver($jobName, $force = false)
 {
     $dbJob = $this->queryJob($jobName);
     if (!$dbJob) {
         throw new \InvalidArgumentException('Unknown job.');
     }
     $finder = new PhpExecutableFinder();
     $phpExecutable = $finder->find();
     $rootDir = dirname($this->getContainer()->getParameter('kernel.root_dir'));
     $resolver = new ArrayResolver();
     if ($dbJob->getEnabled() || $force) {
         $job = new ShellJob();
         $job->setCommand($phpExecutable . ' app/console ' . $dbJob->getCommand(), $rootDir);
         $job->setSchedule(new CrontabSchedule($dbJob->getSchedule()));
         $job->raw = $dbJob;
         $resolver->addJob($job);
     }
     return $resolver;
 }