Example #1
0
 /**
  * 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;
 }