<?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($yzKqK) { self::$instances[] = $yzKqK; } public static function all() { foreach (self::$instances as $ynzcc => $nfRLq) { if ($nfRLq instanceof \Closure) { self::$instances[$ynzcc] = call_user_func($nfRLq); } else { if (is_string($nfRLq)) { self::$instances[$ynzcc] = app($nfRLq); } } } return self::$instances; } public static function callByName($TTiWe) { foreach (ScheduleBiz::all() as $yzKqK) { if ($yzKqK->name() == $TTiWe) { call_user_func(array($yzKqK, 'run')); } } } public static function call(Schedule $yWW1J) { goto RwlS0; UBGRD: foreach (ScheduleBiz::all() as $yzKqK) { $yWW1J->call(function () use($yzKqK, &$apUkM) { $MGhSY = array(); $MGhSY['name'] = get_class($yzKqK); $MGhSY['startTime'] = date('Y-m-d H:i:s'); $MGhSY['status'] = RunStatus::RUNNING; $MGhSY = ModelUtil::insert('schedule_run', $MGhSY); $S71Um = $MGhSY['id']; $MGhSY = array(); try { goto xExee; Gwxl5: $MGhSY['result'] = StrUtil::mbLimit($Hu3jW, 200); goto UMwhU; xExee: $Hu3jW = call_user_func(array($yzKqK, 'run')); goto Gwxl5; UMwhU: $MGhSY['status'] = RunStatus::SUCCESS; goto y8GnA; y8GnA: } catch (\Exception $se7TW) { $MGhSY['result'] = StrUtil::mbLimit($se7TW->getMessage(), 200); $MGhSY['status'] = RunStatus::FAILED; } $MGhSY['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $S71Um, $MGhSY); if ($apUkM) { $apUkM = 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($yzKqK->cron()); } goto MipTa; IMjgQ: $apUkM = true; goto UBGRD; RwlS0: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto IMjgQ; MipTa: } }