public function tryLockJob(Entity\Cronjob $job)
    {
        $em = $this->getEm();
        $repo = $em->getRepository('AdfabCore\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;
    }
public function tryLockJob(Entity\Cronjob $job)
    {
        $em = $this->getEm();
        $repo = $em->getRepository('AdfabCore\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;
    }
public function tryLockJob ( Entity \ Cronjob $ job ) { $ em = $ this -> getEm ( ) ; $ repo = $ em -> getRepository ( 'AdfabCore\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 ; }
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
try to acquire a lock on a cron job