コード例 #1
0
 public function setUp()
 {
     parent::setUp();
     $this->sm = Bootstrap::getServiceManager();
     $this->em = $this->sm->get('doctrine.entitymanager.orm_default');
     $cronData1 = new Cronjob();
     $cronData1->setCode('TestCode1');
     $cronData1->setStatus('pending');
     $cronData1->setCreateTime(new \DateTime('2013-11-4'));
     $cronData1->setScheduleTime(new \DateTime('2013-11-4'));
     $cronData2 = new Cronjob();
     $cronData2->setCode('TestCode2');
     $cronData2->setStatus('pending');
     $cronData2->setCreateTime(new \DateTime('2013-11-5'));
     $cronData2->setScheduleTime(new \DateTime('2013-11-5'));
     $this->cronData[] = $cronData1;
     $this->cronData[] = $cronData2;
 }
コード例 #2
0
ファイル: Cron.php プロジェクト: arnaud-hours/PlaygroundCore
 /**
  * try to acquire a lock on a cron job
  *
  * set a job to 'running' only if it is currently 'pending'
  *
  * @param  Entity\Cronjob $job
  * @return bool
  */
 public function tryLockJob(Entity\Cronjob $job)
 {
     $em = $this->getEm();
     $repo = $em->getRepository('PlaygroundCore\\Entity\\Cronjob');
     if ($job->getStatus() === Mapper\Cronjob::STATUS_PENDING) {
         $job->setStatus(Mapper\Cronjob::STATUS_RUNNING);
         $em->persist($job);
         $em->flush();
         // flush() succeeded if reached here;
         // otherwise an Exception would have been thrown
         return true;
     }
     return false;
 }