<?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($sefXk) { self::$instances[] = $sefXk; } public static function all() { foreach (self::$instances as $JdFJR => $PSYn9) { if ($PSYn9 instanceof \Closure) { self::$instances[$JdFJR] = call_user_func($PSYn9); } else { if (is_string($PSYn9)) { self::$instances[$JdFJR] = app($PSYn9); } } } return self::$instances; } public static function callByName($BjHij) { foreach (ScheduleBiz::all() as $sefXk) { if ($sefXk->name() == $BjHij) { call_user_func(array($sefXk, 'run')); } } } public static function call(Schedule $DbD1c) { goto xQYPG; r34qF: $uKH3M = true; goto hBl1E; hBl1E: foreach (ScheduleBiz::all() as $sefXk) { $DbD1c->call(function () use($sefXk, &$uKH3M) { $smBDO = array(); $smBDO['name'] = get_class($sefXk); $smBDO['startTime'] = date('Y-m-d H:i:s'); $smBDO['status'] = RunStatus::RUNNING; $smBDO = ModelUtil::insert('schedule_run', $smBDO); $lV3Ns = $smBDO['id']; $smBDO = array(); try { goto Dh702; Cpw1o: $smBDO['status'] = RunStatus::SUCCESS; goto GK6_o; Dh702: $j3paW = call_user_func(array($sefXk, 'run')); goto CFqzZ; CFqzZ: $smBDO['result'] = StrUtil::mbLimit($j3paW, 200); goto Cpw1o; GK6_o: } catch (\Exception $hSVcc) { $smBDO['result'] = StrUtil::mbLimit($hSVcc->getMessage(), 200); $smBDO['status'] = RunStatus::FAILED; } $smBDO['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $lV3Ns, $smBDO); if ($uKH3M) { $uKH3M = 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($sefXk->cron()); } goto f2Tie; xQYPG: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto r34qF; f2Tie: } }