<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\Provider\Schedule; use Illuminate\Console\Scheduling\Schedule; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\RandomUtil; use ModStart\Core\Util\StrUtil; use ModStart\Core\Util\TimeUtil; class ScheduleProvider { private static $instances = array(); public static function register($tcA2a) { self::$instances[] = $tcA2a; } public static function all() { foreach (self::$instances as $d2HEV => $hf0nR) { if ($hf0nR instanceof \Closure) { self::$instances[$d2HEV] = call_user_func($hf0nR); } else { if (is_string($hf0nR)) { self::$instances[$d2HEV] = app($hf0nR); } } } return self::$instances; } public static function callByName($SeTC_) { foreach (ScheduleBiz::all() as $tcA2a) { if ($tcA2a->name() == $SeTC_) { call_user_func(array($tcA2a, 'run')); } } } public static function call(Schedule $vnkic) { goto ihM4X; P1KBi: $u_621 = true; goto kR2kQ; kR2kQ: foreach (ScheduleBiz::all() as $tcA2a) { $vnkic->call(function () use($tcA2a, &$u_621) { $q62oK = array(); $q62oK['name'] = get_class($tcA2a); $q62oK['startTime'] = date('Y-m-d H:i:s'); $q62oK['status'] = RunStatus::RUNNING; $q62oK = ModelUtil::insert('schedule_run', $q62oK); $mP43d = $q62oK['id']; $q62oK = array(); try { goto YdXVs; e15Pp: $q62oK['status'] = RunStatus::SUCCESS; goto xsPHz; Vn8e_: $q62oK['result'] = StrUtil::mbLimit($sqdZL, 200); goto e15Pp; YdXVs: $sqdZL = call_user_func(array($tcA2a, 'run')); goto Vn8e_; xsPHz: } catch (\Exception $cknMI) { $q62oK['result'] = StrUtil::mbLimit($cknMI->getMessage(), 200); $q62oK['status'] = RunStatus::FAILED; } $q62oK['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $mP43d, $q62oK); if ($u_621) { $u_621 = false; if (RandomUtil::percent(10)) { ModelUtil::model('schedule_run')->where('created_at', '<', date('Y-m-d H:i:s', time() - TimeUtil::PERIOD_DAY * 7))->delete(); } } })->cron($tcA2a->cron()); } goto ISLlq; ihM4X: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto P1KBi; ISLlq: } }