<?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($tDnAb) { self::$instances[] = $tDnAb; } public static function all() { foreach (self::$instances as $KAKiA => $Iim2u) { if ($Iim2u instanceof \Closure) { self::$instances[$KAKiA] = call_user_func($Iim2u); } else { if (is_string($Iim2u)) { self::$instances[$KAKiA] = app($Iim2u); } } } return self::$instances; } public static function callByName($zO6V5) { foreach (ScheduleBiz::all() as $tDnAb) { if ($tDnAb->name() == $zO6V5) { call_user_func(array($tDnAb, 'run')); } } } public static function call(Schedule $r0ANF) { goto p_nA3; p_nA3: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto h3a9v; h3a9v: $e529Y = true; goto tziDL; tziDL: foreach (ScheduleBiz::all() as $tDnAb) { $r0ANF->call(function () use($tDnAb, &$e529Y) { $avcnU = array(); $avcnU['name'] = get_class($tDnAb); $avcnU['startTime'] = date('Y-m-d H:i:s'); $avcnU['status'] = RunStatus::RUNNING; $avcnU = ModelUtil::insert('schedule_run', $avcnU); $ySxT6 = $avcnU['id']; $avcnU = array(); try { goto myDdK; Pf_un: $avcnU['status'] = RunStatus::SUCCESS; goto ztLox; myDdK: $AzbSd = call_user_func(array($tDnAb, 'run')); goto kR5WL; kR5WL: $avcnU['result'] = StrUtil::mbLimit($AzbSd, 200); goto Pf_un; ztLox: } catch (\Exception $qoTNG) { $avcnU['result'] = StrUtil::mbLimit($qoTNG->getMessage(), 200); $avcnU['status'] = RunStatus::FAILED; } $avcnU['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $ySxT6, $avcnU); if ($e529Y) { $e529Y = 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($tDnAb->cron()); } goto Jvatl; Jvatl: } }