/** 
  * This function takes a look at the schedulers_times table and pulls the
  * jobs to be run at this moment in time (anything not run and with a run
  * time or earlier than right now)
  * @return	$successful	Boolean flag whether a job(s) is found
  */
 function checkPendingJobs()
 {
     global $sugar_config;
     global $current_user;
     $GLOBALS['log']->debug('');
     $GLOBALS['log']->debug('----->Scheduler checking for qualified jobs to run.');
     if (empty($this->db)) {
         $this->db =& PearDatabase::getInstance();
     }
     $fireTimeMinus = gmdate('Y-m-d H:i:s', strtotime('now -1 min'));
     $fireTimePlus = gmdate('Y-m-d H:i:s', strtotime('now +1 min'));
     // collapse list of schedulers where "catch_up" is 0 and status is "ready" (not "in progress, completed, etc.");
     if ($sugar_config['dbconfig']['db_type'] == 'oci8') {
     } else {
         $q = 'UPDATE schedulers_times st LEFT JOIN schedulers s ON st.scheduler_id = s.id SET st.status = \'not run\' WHERE st.execute_time < ' . db_convert('\'' . $fireTimeMinus . '\'', 'datetime') . ' AND st.status = \'ready\' AND s.catch_up = 0';
     }
     $this->db->query($q);
     $q = 'SELECT DISTINCT st.id, st.scheduler_id, st.status, s.name, s.job FROM schedulers_times st LEFT JOIN schedulers s ON st.scheduler_id = s.id WHERE st.execute_time < ' . db_convert('\'' . $fireTimePlus . '\'', 'datetime') . ' AND st.deleted=0 AND s.deleted=0 AND st.status=\'ready\' AND s.status=\'Active\' ORDER BY s.name';
     $r = $this->db->query($q);
     $count = 0;
     if ($sugar_config['dbconfig']['db_type'] == 'mysql') {
         $loopCount = $this->db->getRowCount($r);
         $GLOBALS['log']->debug('----->Scheduler has ' . $loopCount . ' jobs to fire.');
     }
     while ($a = $this->db->fetchByAssoc($r)) {
         require_once 'modules/SchedulersJobs/SchedulersJob.php';
         $job = new SchedulersJob();
         $paramJob = $a['scheduler_id'];
         $job->fire($sugar_config['site_url'] . '/schedulers.php?type=job&job_id=' . $paramJob . '&record=' . $a['id']);
         $count++;
     }
     if ($count < 1) {
         $GLOBALS['log']->debug('----->Scheduler has found 0 Jobs to fire');
     }
 }
예제 #2
0
    /** 
     * This function takes a look at the schedulers_times table and pulls the
     * jobs to be run at this moment in time (anything not run and with a run
     * time or earlier than right now)
     * @return	$successful	Boolean flag whether a job(s) is found
     */
    function checkPendingJobs()
    {
        global $sugar_config;
        global $timedate;
        $GLOBALS['log']->debug('');
        $GLOBALS['log']->debug('----->Scheduler checking for qualified jobs to run.');
        if (empty($this->db)) {
            $this->db = DBManagerFactory::getInstance();
        }
        $fireTimeMinus = $timedate->asDb($timedate->getNow()->get('-1 minute'));
        $fireTimePlus = $timedate->asDb($timedate->getNow()->get('+1 minute'));
        // collapse list of schedulers where "catch_up" is 0 and status is "ready" (not "in progress, completed, etc.");
        $q = 'UPDATE schedulers_times st
					SET st.status = \'not run\' 
					WHERE st.execute_time < ' . $this->db->convert($this->db->quoted($fireTimeMinus), 'datetime') . '
					AND st.status = \'ready\' 
					AND st.scheduler_id IN (SELECT s.id FROM schedulers s WHERE st.scheduler_id = s.id AND s.catch_up = 0)';
        $this->db->query($q);
        $q = 'SELECT DISTINCT st.id, st.scheduler_id, st.status, s.name, s.job FROM schedulers_times st
		    LEFT JOIN schedulers s ON st.scheduler_id = s.id WHERE st.execute_time < ' . $this->db->convert($this->db->quoted($fireTimeMinus), 'datetime') . ' AND st.deleted=0 AND s.deleted=0 AND st.status=\'ready\' AND s.status=\'Active\' ORDER BY s.name';
        $r = $this->db->query($q);
        $count = 0;
        while ($a = $this->db->fetchByAssoc($r)) {
            $job = new SchedulersJob();
            $paramJob = $a['scheduler_id'];
            $job->fire($sugar_config['site_url'] . '/index.php?entryPoint=schedulers&type=job&job_id=' . $paramJob . '&record=' . $a['id']);
            $count++;
        }
        if ($count < 1) {
            $GLOBALS['log']->debug('----->Scheduler has found 0 Jobs to fire');
        }
    }