コード例 #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;
     }
 }
コード例 #2
0
 public function testDateEnd()
 {
     $testDate = new \DateTime();
     $cronTaskLog = new CronTaskLog();
     $this->assertNull($cronTaskLog->getDateEnd());
     $cronTaskLog->setDateEnd($testDate);
     $this->assertEquals($testDate, $cronTaskLog->getDateEnd());
 }