Пример #1
0
 public function run()
 {
     if (fnmatch('*cli*', php_sapi_name())) {
         $dir = Config::get('dir.schedules', APPLICATION_PATH . DS . 'schedules');
         if (is_dir($dir)) {
             Timer::start();
             Cli::show("Start of execution", 'COMMENT');
             $files = glob($dir . DS . '*.php');
             foreach ($files as $file) {
                 require_once $file;
                 $object = str_replace('.php', '', Arrays::last(explode(DS, $file)));
                 $class = 'Thin\\' . ucfirst(Inflector::camelize($object . '_schedule'));
                 $instance = lib('app')->make($class);
                 $methods = get_class_methods($instance);
                 Cli::show("Start schedule '{$object}'", 'COMMENT');
                 foreach ($methods as $method) {
                     $when = $this->getWhen($instance, $method);
                     $isDue = $this->isDue($object, $method, $when);
                     if (true === $isDue) {
                         Cli::show("Execution of {$object}->{$method}", 'INFO');
                         $instance->{$method}();
                     } else {
                         Cli::show("No need to execute {$object}->{$method}", 'QUESTION');
                     }
                 }
             }
             Cli::show("Time of execution [" . Timer::get() . " s.]", 'SUCCESS');
             Cli::show("end of execution", 'COMMENT');
         }
     }
 }
Пример #2
0
 public static function boot()
 {
     Cli::show("Start of execution", 'COMMENT');
     $cron = Cron::instance();
     $cron->flush();
     Cli::show("End of execution", 'COMMENT');
 }
Пример #3
0
 public static function boot()
 {
     Cli::show("Start of execution", 'COMMENT');
     View::cleanCache();
     Database::cleanCache();
     Utils::cleanCache(true);
     Cli::show("End of execution", 'COMMENT');
 }
Пример #4
0
 public function run($name, $when, $event, $args = [])
 {
     Timer::start();
     Cli::show("Start of execution", 'SUCCESS');
     $db = rdb('cron', 'task');
     $dbCron = $db->firstOrCreate(['name' => $name]);
     $nextDb = $dbCron->next;
     $cron = CronExpression::factory($when);
     $next = $cron->getNextRunDate()->format('Y-m-d-H-i-s');
     list($y, $m, $d, $h, $i, $s) = explode('-', $next, 6);
     $timestamp = mktime($h, $i, $s, $m, $d, $y);
     if ($nextDb) {
         if ($nextDb < $timestamp) {
             Cli::show("Execution {$name}", 'COMMENT');
             call_user_func_array($event, $args);
             $dbCron->setNext($timestamp)->save();
         }
     } else {
         $dbCron->setNext($timestamp)->save();
     }
     Cli::show('Elapsed time: ' . Timer::get() . ' s.', 'INFO');
     Cli::show("End of execution", 'SUCCESS');
 }
Пример #5
0
 public static function cleanCache($dir = null)
 {
     $dir = is_null($dir) ? Conf::get('dir.raw.store', STORAGE_PATH . DS . 'raw') : $dir;
     $dirs = glob($dir . DS . '*', GLOB_NOSORT);
     foreach ($dirs as $dir) {
         if (is_dir($dir)) {
             if (fnmatch('*/sessme.*', $dir) || fnmatch('*/me.*', $dir) || fnmatch('*/temporary.*', $dir)) {
                 $age = filemtime($dir);
                 $diff = time() - $age;
                 \Thin\Cli::show("{$diff}", 'INFO');
                 if ($diff > 3600 || fnmatch('*/temporary.*', $dir)) {
                     File::rmdir($dir);
                     \Thin\Cli::show("delete {$dir}", 'COMMENT');
                 }
             }
         }
     }
     $dir = Conf::get('dir.raw.models', APPLICATION_PATH . DS . 'models' . DS . 'Raw') . DS . 'models/temporary';
     File::rmdir($dir);
 }
Пример #6
0
 public static function cleanCache($dir = null)
 {
     $dir = is_null($dir) ? STORAGE_PATH . DS . 'store' : $dir;
     $dirs = glob($dir . DS . '*', GLOB_NOSORT);
     foreach ($dirs as $dir) {
         if (is_dir($dir)) {
             if (fnmatch('*/sessme.*', $dir) || fnmatch('*/me.*', $dir) || fnmatch('*/temporary.*', $dir)) {
                 $age = filemtime($dir);
                 $diff = time() - $age;
                 Cli::show("{$diff}", 'INFO');
                 if ($diff > 3600 || fnmatch('*/temporary.*', $dir)) {
                     File::rmdir($dir);
                     Cli::show("delete {$dir}", 'COMMENT');
                 }
             }
         }
     }
 }