Exemplo n.º 1
0
 /**
  * Do a job
  * @param int $jobId
  * @throws \InvalidArgumentException
  */
 public function work($jobId)
 {
     $job = new Job();
     if (!$job->load($jobId)) {
         throw new \InvalidArgumentException(sprintf("No job found for Job ID: %s", $jobId));
     }
     $job->setStartedOn(new \DateTime());
     $job->setStartedBy(get_current_user());
     $job->save();
     $this->path = Config::get('base_path');
     $arguments = $job->getArguments();
     $argumentString = implode(" ", array_map(function ($argument) {
         return "\"{$argument}\"";
     }, $arguments));
     $command = new Process("php -f {$this->path}vadmin.php {$job->getCallable()} {$argumentString}");
     while (!$command->isFinished()) {
         sleep(1);
     }
     $job->setFinishedOn(new \DateTime());
     $job->setSummary($command->getOutput());
     $job->save();
 }
Exemplo n.º 2
0
 /**
  * Schedule a single job
  * @param Job $job
  * @param \DateTime $scheduleTime
  * @return boolean
  * @throws \Exception
  */
 protected function _scheduleJob(Job $job, \DateTime $scheduleTime)
 {
     $cronExpr = $this->getExpressionService()->formatCronExpression($job->getCronExpr());
     if (!$this->getExpressionService()->isValidCronExpression($cronExpr)) {
         return FALSE;
     }
     if ($this->canSchedule($cronExpr, $scheduleTime)) {
         $job->setScheduledFor($scheduleTime);
         if (!$job->save()) {
             throw new \Exception(sprintf("Failed to schedule job: %s, reason: %s", $job->getName(), $job->getLastError()));
         }
         $job->setId(NULL);
         //allow it to be saved again
         return true;
     }
     return false;
 }