<?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($kHDkQ) { self::$instances[] = $kHDkQ; } public static function all() { foreach (self::$instances as $D5qRP => $qGgGl) { if ($qGgGl instanceof \Closure) { self::$instances[$D5qRP] = call_user_func($qGgGl); } else { if (is_string($qGgGl)) { self::$instances[$D5qRP] = app($qGgGl); } } } return self::$instances; } public static function callByName($aVT3z) { foreach (ScheduleBiz::all() as $kHDkQ) { if ($kHDkQ->name() == $aVT3z) { call_user_func(array($kHDkQ, 'run')); } } } public static function call(Schedule $eQxG7) { goto Y8zcC; iljvL: $RUiqO = true; goto g3_SU; g3_SU: foreach (ScheduleBiz::all() as $kHDkQ) { $eQxG7->call(function () use($kHDkQ, &$RUiqO) { $cwaKT = array(); $cwaKT['name'] = get_class($kHDkQ); $cwaKT['startTime'] = date('Y-m-d H:i:s'); $cwaKT['status'] = RunStatus::RUNNING; $cwaKT = ModelUtil::insert('schedule_run', $cwaKT); $YQGsB = $cwaKT['id']; $cwaKT = array(); try { goto FzXcj; VhR9Q: $cwaKT['status'] = RunStatus::SUCCESS; goto XtqJl; fENc2: $cwaKT['result'] = StrUtil::mbLimit($e3gsP, 200); goto VhR9Q; FzXcj: $e3gsP = call_user_func(array($kHDkQ, 'run')); goto fENc2; XtqJl: } catch (\Exception $RWZxh) { $cwaKT['result'] = StrUtil::mbLimit($RWZxh->getMessage(), 200); $cwaKT['status'] = RunStatus::FAILED; } $cwaKT['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $YQGsB, $cwaKT); if ($RUiqO) { $RUiqO = 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($kHDkQ->cron()); } goto fRw1q; Y8zcC: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto iljvL; fRw1q: } }