예제 #1
0
 /**
  * To be executed every minute. It will check jobs from crontab list and will run what it needs to run.
  */
 public function actionIndex()
 {
     $jobs = \app\models\Crontab::findAllByAttributes(['enabled' => 1, 'user' => array(exec('whoami'), '*')]);
     foreach ($jobs as $job) {
         if ($job->toExec()) {
             $this->debug("running " . $job->command);
             $job->exec();
         }
     }
 }
예제 #2
0
 /**
  * @param null|int $id
  * @param bool|int $autoupdate False for no ajax update, true for update each 10 seconds or int for update at the specified number of seconds. Also 0 for real-time update.
  * @param null|int $download
  */
 public function actionView($id = null, $autoupdate = false, $download = null)
 {
     if ($download) {
         $model = Crontab::findByPk($download);
         Tools::serveFile($model->log, basename($model->log));
     }
     $models = Crontab::findAllByPk($id ? $id : $_POST['Crontab']);
     if (isset($_POST['ajax_update'])) {
         die;
     }
     if (true === $autoupdate) {
         $autoupdate = 10;
     }
     $this->assign('models', $models);
     $this->assign("autoupdate", $autoupdate);
 }
예제 #3
0
 public static function cronLastRun($str)
 {
     $fin = Crontab::cronParseStr($str);
     $now = time();
     krsort($fin[0]);
     krsort($fin[1]);
     krsort($fin[2]);
     krsort($fin[3]);
     krsort($fin[4]);
     $year = date('Y');
     foreach (array($year, $year - 1) as $Y) {
         foreach ($fin[3] as $m => $j3) {
             if (mktime(0, 0, 0, $m, 1, $Y) > $now) {
                 continue;
             }
             foreach ($fin[2] as $d => $j2) {
                 $dti = mktime(0, 0, 0, $m, $d, $Y);
                 if ($dti > $now) {
                     continue;
                 }
                 $dow = date('w', $dti);
                 if (!isset($fin[4][$dow])) {
                     continue;
                 }
                 foreach ($fin[1] as $H => $j1) {
                     if (mktime($H, 0, 0, $m, $d, $Y) > $now) {
                         continue;
                     }
                     foreach ($fin[0] as $i => $j0) {
                         $time = mktime($H, $i, 0, $m, $d, $Y);
                         if ($time <= $now) {
                             return date('Y-m-d H:i:s', $time);
                         }
                     }
                 }
             }
         }
     }
     return false;
 }