/** * 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; }