<?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($oMd7I) { self::$instances[] = $oMd7I; } public static function all() { foreach (self::$instances as $kEhTf => $y2Ltn) { if ($y2Ltn instanceof \Closure) { self::$instances[$kEhTf] = call_user_func($y2Ltn); } else { if (is_string($y2Ltn)) { self::$instances[$kEhTf] = app($y2Ltn); } } } return self::$instances; } public static function callByName($L1N0l) { foreach (ScheduleBiz::all() as $oMd7I) { if ($oMd7I->name() == $L1N0l) { call_user_func(array($oMd7I, 'run')); } } } public static function call(Schedule $mFkrl) { goto SmuP3; SmuP3: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto dSJRv; jZpKh: foreach (ScheduleBiz::all() as $oMd7I) { $mFkrl->call(function () use($oMd7I, &$wdDxT) { $U8wjN = array(); $U8wjN['name'] = get_class($oMd7I); $U8wjN['startTime'] = date('Y-m-d H:i:s'); $U8wjN['status'] = RunStatus::RUNNING; $U8wjN = ModelUtil::insert('schedule_run', $U8wjN); $lX3su = $U8wjN['id']; $U8wjN = array(); try { goto by1eH; F81FJ: $U8wjN['result'] = StrUtil::mbLimit($nV1c1, 200); goto wP6wx; by1eH: $nV1c1 = call_user_func(array($oMd7I, 'run')); goto F81FJ; wP6wx: $U8wjN['status'] = RunStatus::SUCCESS; goto vHwBn; vHwBn: } catch (\Exception $ZemkG) { $U8wjN['result'] = StrUtil::mbLimit($ZemkG->getMessage(), 200); $U8wjN['status'] = RunStatus::FAILED; } $U8wjN['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $lX3su, $U8wjN); if ($wdDxT) { $wdDxT = 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($oMd7I->cron()); } goto VSUXc; dSJRv: $wdDxT = true; goto jZpKh; VSUXc: } }