Esempio n. 1
0
 private function runCommand($string, $timeout = 0)
 {
     $entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTaskLog');
     try {
         $process = new Process($string);
         $process->setTimeout($timeout);
         $process->start(array($this, 'callbackProcess'));
         $this->cronTaskLog->setPid($process->getPid());
         $entityManager->persist($this->cronTaskLog);
         $entityManager->flush();
         $exitCode = $process->wait();
         $this->cronTaskLog->setDateEnd(new \DateTime());
         if ($exitCode > 0) {
             $this->cronTaskLog->setStatus(CronTaskLog::STATUS_FAILED);
         } elseif ($process->getErrorOutput() != '') {
             $this->cronTaskLog->setStatus(CronTaskLog::STATUS_WARNING);
         } else {
             $this->cronTaskLog->setStatus(CronTaskLog::STATUS_SUCCESS);
         }
         $this->cronTaskLog->setPid(null);
         $entityManager->persist($this->cronTaskLog);
         $entityManager->flush();
         return $exitCode !== 0;
     } catch (\Exception $e) {
         $this->cronTaskLog->setStatus(CronTaskLog::STATUS_FAILED);
         $this->cronTaskLog->setPid(null);
         $this->cronTaskLog->setDateEnd(new \DateTime());
         $entityManager->persist($this->cronTaskLog);
         $entityManager->flush();
         return 1;
     }
 }
 public function testStatus()
 {
     $cronTaskLog = new CronTaskLog();
     $cronTaskLog->setStatus(CronTaskLog::STATUS_SUCCESS);
     $this->assertEquals(CronTaskLog::STATUS_SUCCESS, $cronTaskLog->getStatus());
 }