public function runCrons() { $entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTask'); $cronTaskRepo = $entityManager->getRepository('DspSoftsCronManagerBundle:CronTask'); $cronTasks = $cronTaskRepo->findCronsToLaunch(); foreach ($cronTasks as $cronTask) { $run = true; if (!$cronTask->getRelaunch()) { $run = $this->planificationChecker->isExecutionDue($cronTask->getPlanification()); } if ($run) { if ($this->logger !== null) { $this->logger->info(sprintf('Running Cron Task <info>%s</info>', $cronTask->getName())); } $cli = 'exec ' . $this->kernelRootDir . DIRECTORY_SEPARATOR . 'console dsp:cron:runjob -c ' . $cronTask->getId() . ' &'; if ($this->logger !== null) { $this->logger->info(sprintf('Command line : <info>%s</info>', $cli)); } $process = new Process($cli); $process->setTimeout(0); $process->start(); } else { if ($this->logger !== null) { $this->logger->info(sprintf('Skipping Cron Task <info>%s</info>', $cronTask->getName())); } } } }
/** * @dataProvider providerPlanification */ public function testPlanificationEntry($planification, \DateTime $timestamp, $expected) { $planificationChecker = new PlanificationChecker($timestamp); $actual = $planificationChecker->isExecutionDue($planification); $this->assertEquals($expected, $actual); }