/** * Creates a new cron task * * @param string $name Name for the cron task * @param string $description Description of the cron * @param string $command Command string (i.e.: "cache:clear") * @param string $cronExpression Cron expression (https://en.wikipedia.org/wiki/Cron) * @return TblCronTask * @throws CommandNotExistsException */ public function create($name, $description, $command, $cronExpression) { if (!$this->_commandValidator->commandExists($command)) { throw new CommandNotExistsException($command); } $cronTask = new TblCronTask(); $cronTask->setName($name)->setDescription($description)->setCommand($command)->setCronExpression($cronExpression); $this->_entityManager->persist($cronTask); $this->_entityManager->flush($cronTask); return $cronTask; }
/** * Updates active flag * * @param TblCronTask $cronTask * @param bool $active */ public function updateActive(TblCronTask &$cronTask, $active) { $cronTask->setActive($active); $this->_entityManager->flush($cronTask); }
/** * Starts the cron task * * @param TblCronTask $cronTask */ private function _startTask(TblCronTask $cronTask) { $this->_commandExecute->executeBackgroundCommand($cronTask->getCommand()); $this->_updateCronTask->updateLastRun($cronTask, new \DateTime()); }