public function process()
    {
        $em = $this->getEm();
        $cronRegistry = $this->getCronjobs();
        $pending = $this->getPending();
        $scheduleLifetime = $this->scheduleLifetime * 60; //convert min to sec

        $now = new \DateTime;
        foreach ($pending as $job) {
            $scheduleTime = $job->getScheduleTime();

            if ($scheduleTime > $now) {
                continue;
            }

            try {
                $errorStatus = Mapper\Cronjob::STATUS_ERROR;

                $missedTime = clone $now;
                $timestamp = $missedTime->getTimestamp();
                $timestamp -= $scheduleLifetime;
                $missedTime->setTimestamp($timestamp);

                if ($scheduleTime < $missedTime) {
                    $errorStatus = Mapper\Cronjob::STATUS_MISSED;
                    throw new Exception\RuntimeException(
                        'too late for job'
                    );
                }

                $code = $job->getCode();

                if (!isset($cronRegistry[$code])) {
                    throw new Exception\RuntimeException(sprintf(
                        'job "%s" undefined in cron registry',
                        $code
                    ));
                }

                if (!$this->tryLockJob($job)) {
                    //another cron started this job intermittently. skip.
                    continue;
                }

                //run job now
                $callback = $cronRegistry[$code]['callback'];
                $args = $cronRegistry[$code]['args'];

                $job->setExecuteTime(new \DateTime);
                $em->persist($job);
                $em->flush();

                call_user_func_array($callback, $args);

                $job
                    ->setStatus(Mapper\Cronjob::STATUS_SUCCESS)
                    ->setFinishTime(new \DateTime);

            } catch (\Exception $e) {
                $job
                    ->setStatus($errorStatus)
                    ->setErrorMsg($e->getMessage())
                    ->setStackTrace($e->getTraceAsString());
            }

            $em->persist($job);
            $em->flush();
        }

        return $this;
    }
public function process()
    {
        $em = $this->getEm();
        $cronRegistry = $this->getCronjobs();
        $pending = $this->getPending();
        $scheduleLifetime = $this->scheduleLifetime * 60; //convert min to sec

        $now = new \DateTime;
        foreach ($pending as $job) {
            $scheduleTime = $job->getScheduleTime();

            if ($scheduleTime > $now) {
                continue;
            }

            try {
                $errorStatus = Mapper\Cronjob::STATUS_ERROR;

                $missedTime = clone $now;
                $timestamp = $missedTime->getTimestamp();
                $timestamp -= $scheduleLifetime;
                $missedTime->setTimestamp($timestamp);

                if ($scheduleTime < $missedTime) {
                    $errorStatus = Mapper\Cronjob::STATUS_MISSED;
                    throw new Exception\RuntimeException(
                        'too late for job'
                    );
                }

                $code = $job->getCode();

                if (!isset($cronRegistry[$code])) {
                    throw new Exception\RuntimeException(sprintf(
                        'job "%s" undefined in cron registry',
                        $code
                    ));
                }

                if (!$this->tryLockJob($job)) {
                    //another cron started this job intermittently. skip.
                    continue;
                }

                //run job now
                $callback = $cronRegistry[$code]['callback'];
                $args = $cronRegistry[$code]['args'];

                $job->setExecuteTime(new \DateTime);
                $em->persist($job);
                $em->flush();

                call_user_func_array($callback, $args);

                $job
                    ->setStatus(Mapper\Cronjob::STATUS_SUCCESS)
                    ->setFinishTime(new \DateTime);

            } catch (\Exception $e) {
                $job
                    ->setStatus($errorStatus)
                    ->setErrorMsg($e->getMessage())
                    ->setStackTrace($e->getTraceAsString());
            }

            $em->persist($job);
            $em->flush();
        }

        return $this;
    }
public function process ( ) { $ em = $ this -> getEm ( ) ; $ cronRegistry = $ this -> getCronjobs ( ) ; $ pending = $ this -> getPending ( ) ; $ scheduleLifetime = $ this -> scheduleLifetime * 60 ; //convert min to sec $ now = new \ DateTime ; foreach ( $ pending as $ job ) { $ scheduleTime = $ job -> getScheduleTime ( ) ; if ( $ scheduleTime > $ now ) { continue ; } try { $ errorStatus = Mapper \ Cronjob :: STATUS_ERROR ; $ missedTime = clone $ now ; $ timestamp = $ missedTime -> getTimestamp ( ) ; $ timestamp -= $ scheduleLifetime ; $ missedTime -> setTimestamp ( $ timestamp ) ; if ( $ scheduleTime < $ missedTime ) { $ errorStatus = Mapper \ Cronjob :: STATUS_MISSED ; throw new Exception \ RuntimeException ( 'too late for job' ) ; } $ code = $ job -> getCode ( ) ; if ( ! isset ( $ cronRegistry [ $ code ] ) ) { throw new Exception \ RuntimeException ( sprintf ( 'job "%s" undefined in cron registry' , $ code ) ) ; } if ( ! $ this -> tryLockJob ( $ job ) ) { //another cron started this job intermittently. skip. continue ; } //run job now $ callback = $ cronRegistry [ $ code ] [ 'callback' ] ; $ args = $ cronRegistry [ $ code ] [ 'args' ] ; $ job -> setExecuteTime ( new \ DateTime ) ; $ em -> persist ( $ job ) ; $ em -> flush ( ) ; call_user_func_array ( $ callback , $ args ) ; $ job -> setStatus ( Mapper \ Cronjob :: STATUS_SUCCESS ) -> setFinishTime ( new \ DateTime ) ; } catch ( \ Exception $ e ) { $ job -> setStatus ( $ errorStatus ) -> setErrorMsg ( $ e -> getMessage ( ) ) -> setStackTrace ( $ e -> getTraceAsString ( ) ) ; } $ em -> persist ( $ job ) ; $ em -> flush ( ) ; } return $ this ; }
run cron jobs

@return self
run cron jobs