<?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($O9Vtg) { self::$instances[] = $O9Vtg; } public static function all() { foreach (self::$instances as $MFVkb => $YxV2x) { if ($YxV2x instanceof \Closure) { self::$instances[$MFVkb] = call_user_func($YxV2x); } else { if (is_string($YxV2x)) { self::$instances[$MFVkb] = app($YxV2x); } } } return self::$instances; } public static function callByName($MGY9H) { foreach (ScheduleBiz::all() as $O9Vtg) { if ($O9Vtg->name() == $MGY9H) { call_user_func(array($O9Vtg, 'run')); } } } public static function call(Schedule $kULMT) { goto F8tTu; JxyMa: foreach (ScheduleBiz::all() as $O9Vtg) { $kULMT->call(function () use($O9Vtg, &$Tz_N4) { $Pg57y = array(); $Pg57y['name'] = get_class($O9Vtg); $Pg57y['startTime'] = date('Y-m-d H:i:s'); $Pg57y['status'] = RunStatus::RUNNING; $Pg57y = ModelUtil::insert('schedule_run', $Pg57y); $TreM3 = $Pg57y['id']; $Pg57y = array(); try { goto lkxD1; FD7K0: $Pg57y['status'] = RunStatus::SUCCESS; goto yDHbc; ylZya: $Pg57y['result'] = StrUtil::mbLimit($s2vPN, 200); goto FD7K0; lkxD1: $s2vPN = call_user_func(array($O9Vtg, 'run')); goto ylZya; yDHbc: } catch (\Exception $fWY9h) { $Pg57y['result'] = StrUtil::mbLimit($fWY9h->getMessage(), 200); $Pg57y['status'] = RunStatus::FAILED; } $Pg57y['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $TreM3, $Pg57y); if ($Tz_N4) { $Tz_N4 = 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($O9Vtg->cron()); } goto IF1N3; FGYhY: $Tz_N4 = true; goto JxyMa; F8tTu: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto FGYhY; IF1N3: } }