<?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; use Illuminate\Support\Facades\Log; class ScheduleProvider { private static $instances = array(); public static function register($ugwYT) { self::$instances[] = $ugwYT; } public static function all() { foreach (self::$instances as $QBy8K => $cG5OI) { if ($cG5OI instanceof \Closure) { self::$instances[$QBy8K] = call_user_func($cG5OI); } else { if (is_string($cG5OI)) { self::$instances[$QBy8K] = app($cG5OI); } } } return self::$instances; } public static function callByName($HRrYd) { foreach (self::all() as $ugwYT) { if ($ugwYT->name() == $HRrYd) { call_user_func(array($ugwYT, 'run')); } } } public static function call(Schedule $DZpk5) { $ItSe3 = true; foreach (ScheduleProvider::all() as $ugwYT) { $DZpk5->call(function () use($ugwYT, &$ItSe3) { $xJzrK = array(); $xJzrK['name'] = get_class($ugwYT); $xJzrK['startTime'] = date('Y-m-d H:i:s'); $xJzrK['status'] = RunStatus::RUNNING; $xJzrK = ModelUtil::insert('schedule_run', $xJzrK); $MuDkp = $xJzrK['id']; $xJzrK = array(); try { goto ihUUm; ihUUm: $MZSQT = call_user_func(array($ugwYT, 'run')); goto p53IR; p53IR: $xJzrK['result'] = StrUtil::mbLimit($MZSQT, 200); goto GWWkz; GWWkz: $xJzrK['status'] = RunStatus::SUCCESS; goto hqyVr; hqyVr: } catch (\Exception $Q19lV) { $xJzrK['result'] = StrUtil::mbLimit($Q19lV->getMessage(), 200); $xJzrK['status'] = RunStatus::FAILED; } $xJzrK['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $MuDkp, $xJzrK); if ($ItSe3) { $ItSe3 = 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($ugwYT->cron()); } } }