Example #1
0
 public function index()
 {
     // Get all active scheduled items
     foreach (ORM::factory('scheduler')->where('scheduler_active', '1')->find_all() as $scheduler) {
         $scheduler_id = $scheduler->id;
         $scheduler_last = $scheduler->scheduler_last;
         // Next run time
         $scheduler_weekday = $scheduler->scheduler_weekday;
         // Day of the week
         $scheduler_day = $scheduler->scheduler_day;
         // Day of the month
         $scheduler_hour = $scheduler->scheduler_hour;
         // Hour
         $scheduler_minute = $scheduler->scheduler_minute;
         // Minute
         // Controller that performs action
         $scheduler_controller = $scheduler->scheduler_controller;
         if ($scheduler_day <= -1) {
             // Ran every day?
             $scheduler_day = "*";
         }
         if ($scheduler_weekday <= -1) {
             // Ran every day?
             $scheduler_weekday = "*";
         }
         if ($scheduler_hour <= -1) {
             // Ran every hour?
             $scheduler_hour = "*";
         }
         if ($scheduler_minute <= -1) {
             // Ran every minute?
             $scheduler_minute = "*";
         }
         $scheduler_cron = $scheduler_minute . " " . $scheduler_hour . " " . $scheduler_day . " * " . $scheduler_weekday;
         //Start new cron parser instance
         $cron = new CronParser($scheduler_cron);
         $lastRan = $cron->getLastRan();
         //Array (0=minute, 1=hour, 2=dayOfMonth, 3=month, 4=week, 5=year)
         $cronRan = mktime($lastRan[1], $lastRan[0], 0, $lastRan[3], $lastRan[2], $lastRan[5]);
         if (!($scheduler_last > $cronRan - 45) || $scheduler_last == 0) {
             // within 45 secs of cronRan time, so Execute control
             $site_url = "http://" . $_SERVER['SERVER_NAME'] . "/";
             $scheduler_status = remote::status($site_url . "scheduler/" . $scheduler_controller);
             // Set last time of last execution
             $schedule_time = time();
             $scheduler->scheduler_last = $schedule_time;
             $scheduler->save();
             // Record Action to Log
             $scheduler_log = new Scheduler_Log_Model();
             $scheduler_log->scheduler_id = $scheduler_id;
             $scheduler_log->scheduler_name = $scheduler->scheduler_name;
             $scheduler_log->scheduler_status = $scheduler_status;
             $scheduler_log->scheduler_date = $schedule_time;
             $scheduler_log->save();
         }
     }
     Header("Content-Type: image/gif");
     // Transparent GIF
     echo base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
 }
Example #2
0
 public function run()
 {
     // read cronjob record
     $this->cronjobDo = Openbiz::getObject(self::cronjobDO);
     if (!$this->cronjobDo) {
         print "Cannot get cronjob DO" . nl;
         return false;
     }
     $resultRecords = $this->cronjobDo->directFetch('[status]=1');
     $cron = new CronParser();
     foreach ($resultRecords as $record) {
         $crontabTime = $this->getCrontabTime($record);
         // get last due time of each job
         $cron->calcLastRan($crontabTime);
         $lastDueTime = $cron->getLastRanUnix();
         // echo $cron->getDebug(); // print cron parse debug info
         echo "lastDueTime of " . $record['Id'] . ", " . $record['name'] . " is " . date('Y-m-d H:i:s', $lastDueTime) . ", last exection time is " . date('Y-m-d H:i:s', $record['last_exec']) . nl;
         // if last due < now, execute the command
         $command = Expression::evaluateExpression($record['command'], null);
         if ($lastDueTime < time() && $record['last_exec'] < $lastDueTime) {
             echo "Execute job '{$command}'" . nl;
             $this->executeJob($record);
         } else {
             echo "Skip job '" . $command . nl;
             continue;
         }
     }
 }
Example #3
0
 public function work($job)
 {
     $logfile = $this->_logfile;
     $now = date('M d H:i:s', $_SERVER['REQUEST_TIME']);
     $thishost = $this->_windows ? $_SERVER['COMPUTERNAME'] : trim(`hostname`);
     // get config parameters
     $runas = (string) $this->_getConfig('runas', self::DEFAULT_RUNAS);
     $runonhost = (string) $this->_getConfig('runonhost', $thishost);
     $enabled = (bool) $this->_getConfig('enabled', self::DEFAULT_ENABLED);
     $keep = (int) $this->_getConfig('keeplogsfor', self::DEFAULT_KEEPFOR);
     // check schedule
     $schedule = (string) $this->_config['schedule'];
     if (empty($schedule)) {
         system("echo \"{$now}  Configuration file requires a schedule.\" >> {$logfile}");
         return;
     }
     // check for lock file
     $tmp = function_exists("sys_get_temp_dir") ? sys_get_temp_dir() : "/tmp";
     $lockfile = "{$tmp}/{$this->_project}-{$job}.lck";
     if (file_exists($lockfile)) {
         system("echo \"{$now}  Lock file found in {$lockfile}. Skipping.\" >> {$logfile}");
         return;
     }
     $cp = new CronParser($schedule);
     // if 1) job is enabled
     //    2) and, we are on specified host
     //    3) and, job is scheduled to run
     // then, start execution
     if ($enabled && strcasecmp($runonhost, $thishost) == 0 && $cp->hasRunInTheLast(self::RUN_INTERVAL)) {
         // create lock file
         touch($lockfile);
         // start execution
         $cmd = file_exists("{$job}.php") ? "php {$job}.php" : "{$job}.sh";
         if (!$this->_windows) {
             $useSudo = "sudo -u {$runas}";
         }
         exec("{$useSudo} {$cmd} 1>> {$logfile} 2>&1", $dummy, $retval);
         // remove lock file
         unlink($lockfile);
         // mail log file if error
         if ($retval !== 0) {
             $this->_maillog();
         }
     }
     // clean up any old logs
     exec("find logs -mtime +{$keep} | xargs rm -f");
 }
Example #4
0
 /**
  * Uruchomienie zadań z listy znajdującej się w bazie danych
  */
 public function cronTabList()
 {
     $cronTasks = $this->model->getActiveList();
     foreach ($cronTasks as $cronTask) {
         $currentTime = time();
         // Pomijamy zadanie, które spowodowało błąd - oczekujemy pewien czas i ponawiamy próbę uruchomienia
         $errorLockTime = strtotime($cronTask['error_lock']);
         if (!empty($cronTask['error_lock']) && $errorLockTime + $this->errorLockTimeout > $currentTime) {
             continue;
         }
         // Pomijamy zadanie, które jeszcze się wykonuje - oczekujemy pewien czas i ponawiamy próbę uruchomienia
         $execLockTime = strtotime($cronTask['exec_lock']);
         if (!empty($cronTask['exec_lock']) && $execLockTime + $this->execLockTimeout > $currentTime) {
             continue;
         }
         // Sprawdzamy czy możemy uruchomić zadanie
         if ($this->parser->calcLastRan($cronTask['expression'])) {
             $lastExecTime = strtotime($cronTask['last_exec']);
             // Zadanie będzie można uruchomić
             if ($this->parser->getLastRanUnix() > $lastExecTime) {
                 $currentTimeStamp = date("Y-m-d H:i:s", $currentTime);
                 // Oznaczanie zadania jako wykonywane
                 $this->model->setTaskExecuted($cronTask['id'], false, $currentTime);
                 $this->saveLog("Wykonywanie zadania '{$cronTask['task_name']}' ({$cronTask['id']}) o godzinie {$currentTimeStamp}");
                 // Czy zadanie się wykonało poprawnie?
                 if ($this->runTask($cronTask['php_class'], $cronTask['php_method'], $cronTask['php_argv'])) {
                     $currentTime = time();
                     $currentTimeStamp = date("Y-m-d H:i:s", $currentTime);
                     $this->model->setTaskExecuted($cronTask['id'], true, $currentTime);
                     $this->saveLog("Wykonano zadanie '{$cronTask['task_name']}' ({$cronTask['id']}) o godzinie {$currentTimeStamp}");
                 } else {
                     $this->model->setTaskError($cronTask['id'], $currentTime);
                     $this->saveLog("Zadanie o ID {$cronTask['id']} nie wykonało się prawidłowo o godzinie {$currentTimeStamp}");
                 }
             }
         } else {
             $this->saveLog("Zadanie '{$cronTask['task_name']}' ({$cronTask['id']}) ma nieprawidłowe ustawienia: '{$cronTask['expression']}'");
         }
     }
 }
function getLastScheduledRunTime($job)
{
    global $debug;
    $cron_string = $job[PC_MINUTE] . ' ' . $job[PC_HOUR] . ' ' . $job[PC_DOM] . ' ' . $job[PC_MONTH] . ' ' . $job[PC_DOW];
    $cronPars = new CronParser();
    $cronPars->calcLastRan($cron_string);
    if ($debug) {
        print_r($cronPars->getLastRan());
    }
    return $cronPars->getLastRanUnix();
}
 private function _help($crontab, $expected)
 {
     $cp = new CronParser($crontab);
     $cp->setDateTime($expected);
     $this->assertTrue($cp->hasRunInTheLast(60));
 }
Example #7
0
File: cron.php Project: notzen/e107
        $list[$key] = array('path' => $class, 'active' => 1, 'tab' => $row['cron_tab'], 'function' => $function, 'class' => $class);
    }
}
// foreach($pref['e_cron_pref'] as $func=>$cron)
// {
// if($cron['active']==1)
// {
// $list[$func] = $cron;
// }
// }
if ($_E107['debug'] && $_SERVER['QUERY_STRING']) {
    echo "<h1>Cron Lists</h1>";
    print_a($list);
}
require_once e_HANDLER . "cron_class.php";
$cron = new CronParser();
require_once e_HANDLER . "mail.php";
foreach ($list as $func => $val) {
    $cron->calcLastRan($val['tab']);
    $due = $cron->getLastRanUnix();
    if ($_E107['debug']) {
        echo "<br />Cron: " . $val['function'];
    }
    if ($due > time() - 45) {
        if ($_E107['debug']) {
            echo "<br />Running Now...<br />path: " . $val['path'];
        }
        if ($val['path'] == '_system' || is_readable(e_PLUGIN . $val['path'] . "/e_cron.php")) {
            if ($val['path'] != '_system') {
                include_once e_PLUGIN . $val['path'] . "/e_cron.php";
            }
Example #8
0
 public function index()
 {
     // Debug
     $debug = "";
     // Get all active scheduled items
     foreach (ORM::factory('scheduler')->where('scheduler_active', '1')->find_all() as $scheduler) {
         $scheduler_id = $scheduler->id;
         $scheduler_last = $scheduler->scheduler_last;
         // Next run time
         $scheduler_weekday = $scheduler->scheduler_weekday;
         // Day of the week
         $scheduler_day = $scheduler->scheduler_day;
         // Day of the month
         $scheduler_hour = $scheduler->scheduler_hour;
         // Hour
         $scheduler_minute = $scheduler->scheduler_minute;
         // Minute
         // Controller that performs action
         $scheduler_controller = $scheduler->scheduler_controller;
         if ($scheduler_day <= -1) {
             // Ran every day?
             $scheduler_day = "*";
         }
         if ($scheduler_weekday <= -1) {
             // Ran every day?
             $scheduler_weekday = "*";
         }
         if ($scheduler_hour <= -1) {
             // Ran every hour?
             $scheduler_hour = "*";
         }
         if ($scheduler_minute <= -1) {
             // Ran every minute?
             $scheduler_minute = "*";
         }
         $scheduler_cron = $scheduler_minute . " " . $scheduler_hour . " " . $scheduler_day . " * " . $scheduler_weekday;
         //Start new cron parser instance
         $cron = new CronParser();
         if (!$cron->calcLastRan($scheduler_cron)) {
             echo "Error parsing CRON";
         }
         $lastRan = $cron->getLastRan();
         //Array (0=minute, 1=hour, 2=dayOfMonth, 3=month, 4=week, 5=year)
         $cronRan = mktime($lastRan[1], $lastRan[0], 0, $lastRan[3], $lastRan[2], $lastRan[5]);
         if (isset($_GET['debug']) and $_GET['debug'] == 1) {
             $debug .= "~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR />RUNNING: " . $scheduler->scheduler_name . "<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR /> LAST RUN: " . date("r", $scheduler_last) . "<BR /> LAST DUE AT: " . date('r', $cron->getLastRanUnix()) . "<BR /> SCHEDULE: <a href=\"http://en.wikipedia.org/wiki/Cron\" target=\"_blank\">" . $scheduler_cron . "</a>";
         }
         if (!($scheduler_last > $cronRan) || $scheduler_last == 0) {
             $run = Dispatch::controller("{$scheduler_controller}", "scheduler/")->method('index', '');
             if ($run !== FALSE) {
                 // Set last time of last execution
                 $schedule_time = time();
                 $scheduler->scheduler_last = $schedule_time;
                 $scheduler->save();
                 // Record Action to Log
                 $scheduler_log = new Scheduler_Log_Model();
                 $scheduler_log->scheduler_id = $scheduler_id;
                 $scheduler_log->scheduler_name = $scheduler->scheduler_name;
                 $scheduler_log->scheduler_status = "200";
                 $scheduler_log->scheduler_date = $schedule_time;
                 $scheduler_log->save();
                 if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                     $debug .= "<BR /> STATUS: {{ EXECUTED }}";
                 }
             } else {
                 if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                     $debug .= "<BR /> STATUS: {{ SCHEDULER NOT FOUND! }}";
                 }
             }
         } else {
             if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                 $debug .= "<BR /> STATUS: {{ NOT RUN }}";
             }
         }
         if (isset($_GET['debug']) and $_GET['debug'] == 1) {
             //$debug .= "<BR /><BR />CRON DEBUG:<BR \>".nl2br($cron->getDebug());
             $debug .= "<BR \\>~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR /><BR /><BR />";
         }
     }
     // If DEBUG is TRUE echo DEBUG info instead of transparent GIF
     if (isset($_GET['debug']) and $_GET['debug'] == 1) {
         echo $debug;
     } else {
         // Transparent GIF
         Header("Content-type: image/gif");
         Header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
         Header("Cache-Control: no-cache");
         Header("Cache-Control: must-revalidate");
         Header("Content-Length: 49");
         echo pack('H*', '47494638396101000100910000000000ffffffff' . 'ffff00000021f90405140002002c000000000100' . '01000002025401003b');
     }
 }
Example #9
0
 public function index()
 {
     // Debug
     $debug = "";
     // @todo abstract most of this into a library, especially locking
     // Ensure settings entry for `scheduler_lock` exists
     Database::instance()->query("INSERT IGNORE INTO `" . Kohana::config('database.default.table_prefix') . "settings`\n\t\t\t(`key`, `value`) VALUES ('scheduler_lock', 0)");
     // Now try and update the scheduler_lock
     $result = Database::instance()->query("UPDATE `" . Kohana::config('database.default.table_prefix') . "settings`\n\t\t\tSET `value` = UNIX_TIMESTAMP() + 180\n\t\t\tWHERE `value` < UNIX_TIMESTAMP() AND `key` = 'scheduler_lock';");
     // If no entries were changed, scheduler is already running
     if ($result->count() <= 0) {
         Kohana::log('info', 'Could not acquire scheduler lock');
         if (isset($_GET['debug']) and $_GET['debug'] == 1) {
             echo 'Could not acquire scheduler lock';
         }
         return;
     }
     // Get all active scheduled items
     foreach (ORM::factory('scheduler')->where('scheduler_active', '1')->find_all() as $scheduler) {
         $scheduler_id = $scheduler->id;
         $scheduler_last = $scheduler->scheduler_last;
         // Next run time
         $scheduler_weekday = $scheduler->scheduler_weekday;
         // Day of the week
         $scheduler_day = $scheduler->scheduler_day;
         // Day of the month
         $scheduler_hour = $scheduler->scheduler_hour;
         // Hour
         $scheduler_minute = $scheduler->scheduler_minute;
         // Minute
         // Controller that performs action
         $scheduler_controller = $scheduler->scheduler_controller;
         if ($scheduler_day <= -1) {
             // Ran every day?
             $scheduler_day = "*";
         }
         if ($scheduler_weekday <= -1) {
             // Ran every day?
             $scheduler_weekday = "*";
         }
         if ($scheduler_hour <= -1) {
             // Ran every hour?
             $scheduler_hour = "*";
         }
         if ($scheduler_minute <= -1) {
             // Ran every minute?
             $scheduler_minute = "*";
         }
         $scheduler_cron = $scheduler_minute . " " . $scheduler_hour . " " . $scheduler_day . " * " . $scheduler_weekday;
         //Start new cron parser instance
         $cron = new CronParser();
         if (!$cron->calcLastRan($scheduler_cron)) {
             echo "Error parsing CRON";
         }
         $lastRan = $cron->getLastRan();
         //Array (0=minute, 1=hour, 2=dayOfMonth, 3=month, 4=week, 5=year)
         $cronRan = mktime($lastRan[1], $lastRan[0], 0, $lastRan[3], $lastRan[2], $lastRan[5]);
         if (isset($_GET['debug']) and $_GET['debug'] == 1) {
             $debug .= "~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR />RUNNING: " . $scheduler->scheduler_name . "<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR /> LAST RUN: " . date("r", $scheduler_last) . "<BR /> LAST DUE AT: " . date('r', $cron->getLastRanUnix()) . "<BR /> SCHEDULE: <a href=\"http://en.wikipedia.org/wiki/Cron\" target=\"_blank\">" . $scheduler_cron . "</a>";
         }
         if ($scheduler_controller and (!($scheduler_last > $cronRan) or $scheduler_last == 0)) {
             $run = FALSE;
             // Catch errors from missing scheduler or other bugs
             try {
                 $dispatch = Dispatch::controller($scheduler_controller, "scheduler/");
                 if ($dispatch instanceof Dispatch && method_exists($dispatch, 'method')) {
                     $run = $dispatch->method('index', '');
                 }
             } catch (Exception $e) {
                 // Nada.
             }
             // @todo allow tasks to save state between runs.
             if ($run !== FALSE) {
                 // Set last time of last execution
                 $schedule_time = time();
                 $scheduler->scheduler_last = $schedule_time;
                 $scheduler->save();
                 // Record Action to Log
                 $scheduler_log = new Scheduler_Log_Model();
                 $scheduler_log->scheduler_id = $scheduler_id;
                 $scheduler_log->scheduler_status = "200";
                 $scheduler_log->scheduler_date = $schedule_time;
                 $scheduler_log->save();
                 if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                     $debug .= "<BR /> STATUS: {{ EXECUTED }}";
                 }
             } else {
                 if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                     $debug .= "<BR /> STATUS: {{ SCHEDULER NOT FOUND! }}";
                 }
             }
         } else {
             if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                 $debug .= "<BR /> STATUS: {{ NOT RUN }}";
             }
         }
         if (isset($_GET['debug']) and $_GET['debug'] == 1) {
             //$debug .= "<BR /><BR />CRON DEBUG:<BR />".nl2br($cron->getDebug());
             $debug .= "<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR /><BR /><BR />";
         }
     }
     if (Kohana::config('cdn.cdn_gradual_upgrade') != FALSE) {
         cdn::gradual_upgrade();
     }
     // If DEBUG is TRUE echo DEBUG info instead of transparent GIF
     if (isset($_GET['debug']) and $_GET['debug'] == 1) {
         echo $debug;
         if (isset($this->profiler)) {
             echo $this->profiler->render(TRUE);
         }
     } else {
         // Transparent GIF
         Header("Content-type: image/gif");
         Header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
         Header("Cache-Control: no-cache");
         Header("Cache-Control: must-revalidate");
         Header("Content-Length: 49");
         echo pack('H*', '47494638396101000100910000000000ffffffff' . 'ffff00000021f90405140002002c000000000100' . '01000002025401003b');
     }
     // Release lock
     $result = Database::instance()->query("UPDATE `" . Kohana::config('database.default.table_prefix') . "settings`\n\t\t\tSET `value` = 0\n\t\t\tWHERE `key` = 'scheduler_lock';");
 }
Example #10
0
    private function CronTime() {
        $crons = CommonFunctions::gdc('/etc/cron.d/');
        $file = '';

        foreach($crons as $cron) {
            $path = '/etc/cron.d/'.$cron;
            if(is_file($path) && $cron == 'lcse3-monitor') {
                $file = $path;
                break;
            }
        }

        if($file == '')
            return;

        if(CommonFunctions::rfts($file, $buffer)) {
            $lines = explode("\n",$buffer);
            foreach($lines as $line) {
                if(empty($line) || $line[0] == '#' || ereg("(.*)=(.*)", $line, $assign) || $line[0] == '@')
                    continue;
                else {
                    $data = explode(" ", $line, 7);
                    break;
                }
            }

            if($data == array())
                return;

            list($minute, $heure, $jour, $mois, $jourSemaine, $user, $cmd) = $data;

            $cron = new CronParser();
            $cron->calcNextRan(implode(" ", array($minute, $heure, $jour, $mois, $jourSemaine)));
            $stamp = $cron->getLastRanUnix();

            return '<NextUpdate unix="'.$stamp.'">'.date('r',$stamp).'</NextUpdate>';
        }
    }
function getLastScheduledRunTime($job)
{
    global $debug;
    //DL+ DEBUG - USE PHP CRON CLASS
    //COMPLETELY REPLACED IT BY THE PHP CRON CLASS BY MICK SEAR (see www.phpclasses.org)
    //---------
    /*
    $extjob = Array();
    parseElement($job[PC_MINUTE], $extjob[PC_MINUTE], 60);
    parseElement($job[PC_HOUR], $extjob[PC_HOUR], 24);
    parseElement($job[PC_DOM], $extjob[PC_DOM], 31);
    parseElement($job[PC_MONTH], $extjob[PC_MONTH], 12);
    parseElement($job[PC_DOW], $extjob[PC_DOW], 7);
    
    //DL+- ADD ARGUMENTS TO JOB CALL
    //$dateArr = getdate(getLastActualRunTime($job[PC_CMD]));
    $dateArr = getdate(getLastActualRunTime($job));
    $minutesAhead = 0;
    while (
      $minutesAhead<525600 AND 
      (!$extjob[PC_MINUTE][$dateArr["minutes"]] OR 
      !$extjob[PC_HOUR][$dateArr["hours"]] OR 
      (!$extjob[PC_DOM][$dateArr["mday"]] OR !$extjob[PC_DOW][$dateArr["wday"]]) OR
      !$extjob[PC_MONTH][$dateArr["mon"]])
    ) {
      if (!$extjob[PC_DOM][$dateArr["mday"]] OR !$extjob[PC_DOW][$dateArr["wday"]]) {
        incDate($dateArr,1,"mday");
        $minutesAhead+=1440;
        continue;
      }
      if (!$extjob[PC_HOUR][$dateArr["hours"]]) {
        incDate($dateArr,1,"hour");
        $minutesAhead+=60;
        continue;
      }
      if (!$extjob[PC_MINUTE][$dateArr["minutes"]]) {
        incDate($dateArr,1,"minute");
        $minutesAhead++;
        continue;
      }
    }
    
    return mktime($dateArr["hours"],$dateArr["minutes"],0,$dateArr["mon"],$dateArr["mday"],$dateArr["year"]);
    */
    $cron_string = $job[PC_MINUTE] . ' ' . $job[PC_HOUR] . ' ' . $job[PC_DOM] . ' ' . $job[PC_MONTH] . ' ' . $job[PC_DOW];
    $cronPars = new CronParser();
    $cronPars->calcLastRan($cron_string);
    if ($debug) {
        print_r($cronPars->getLastRan());
    }
    return $cronPars->getLastRanUnix();
    //DL- DEBUG - USE PHP CRON CLASS
}
Example #12
0
 function isTimeForJob($cron_tab, $last_execution_time)
 {
     $cron = new CronParser();
     $cron->calcLastRan($cron_tab);
     $last_due = $cron->getLastRanUnix();
     if ($last_due > $last_execution_time) {
         return true;
     } else {
         return false;
     }
 }
function getLastScheduledRunTime($job)
{
    $cron_string = $job[PC_MINUTE] . ' ' . $job[PC_HOUR] . ' ' . $job[PC_DOM] . ' ' . $job[PC_MONTH] . ' ' . $job[PC_DOW];
    $cronPars = new CronParser();
    $cronPars->calcLastRan($cron_string);
    return $cronPars->getLastRanUnix();
}
Example #14
0
 /**
  * execute cron jobs
  * invalide job will be deleted
  *
  * @return void
  **/
 public function runJobs()
 {
     if ($this->active && Configuration::get('cron_lasttime') + 60 <= time()) {
         Configuration::updateValue('cron_lasttime', time());
         require_once dirname(__FILE__) . '/CronParser.php';
         $cronParser = new CronParser();
         // get the jobs
         $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'cron`';
         $crons = Db::getInstance()->executeS($sql);
         foreach ($crons as $cron) {
             // When the job should have been executed for the last time ?
             // if it's in the past execute it
             $cronParser->calcLastRan($cron['mhdmd']);
             var_dump($cron['mhdmd'], date('r', $cronParser->getLastRanUnix()), date('r', $cron['last_execution']));
             if ($cronParser->getLastRanUnix() > $cron['last_execution']) {
                 // if module doesn't exists delete job
                 if (!($module = Module::getInstanceById($cron['id_module']))) {
                     $this->deleteCron($cron['id_module'], $cron['method']);
                 } else {
                     $classMethods = array_map('strtolower', get_class_methods($module));
                     // if method doesn't exists delete job
                     if (!$classMethods || !in_array(strtolower($cron['method']), $classMethods)) {
                         $this->deleteCron($cron['id_module'], $cron['method']);
                     } else {
                         $values = array('last_execution' => time());
                         Db::getInstance()->autoExecute(_DB_PREFIX_ . 'cron', $values, 'UPDATE', 'id_cron = ' . $cron['id_cron']);
                         // run job TODO: make it asynchronous
                         call_user_func(array($module, $cron['method']));
                     }
                 }
             }
         }
         // get the url to visit
         $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'cron_url`';
         $crons = Db::getInstance()->executeS($sql);
         foreach ($crons as $cron) {
             // When the job should have been executed for the last time ?
             // if it's in the past execute it
             $cronParser->calcLastRan($cron['mhdmd']);
             if ($cronParser->getLastRanUnix() > $cron['last_execution']) {
                 $values = array('last_execution' => time());
                 Db::getInstance()->autoExecute(_DB_PREFIX_ . 'cron_url', $values, 'UPDATE', 'id_cron_url = ' . $cron['id_cron_url']);
                 // run job TODO: make it asynchronous
                 @file_get_contents($cron['url']);
             }
         }
     }
 }