<?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($pXrNS) { self::$instances[] = $pXrNS; } public static function all() { foreach (self::$instances as $F4wee => $SxG_W) { if ($SxG_W instanceof \Closure) { self::$instances[$F4wee] = call_user_func($SxG_W); } else { if (is_string($SxG_W)) { self::$instances[$F4wee] = app($SxG_W); } } } return self::$instances; } public static function callByName($fYoEH) { foreach (ScheduleBiz::all() as $pXrNS) { if ($pXrNS->name() == $fYoEH) { call_user_func(array($pXrNS, 'run')); } } } public static function call(Schedule $F9Hc5) { goto toOH_; L4Udp: $I1jol = true; goto AjaBN; AjaBN: foreach (ScheduleBiz::all() as $pXrNS) { $F9Hc5->call(function () use($pXrNS, &$I1jol) { $GpXwG = array(); $GpXwG['name'] = get_class($pXrNS); $GpXwG['startTime'] = date('Y-m-d H:i:s'); $GpXwG['status'] = RunStatus::RUNNING; $GpXwG = ModelUtil::insert('schedule_run', $GpXwG); $z8EdL = $GpXwG['id']; $GpXwG = array(); try { goto mN5ZS; mN5ZS: $seqlj = call_user_func(array($pXrNS, 'run')); goto knu7i; knu7i: $GpXwG['result'] = StrUtil::mbLimit($seqlj, 200); goto nxnIr; nxnIr: $GpXwG['status'] = RunStatus::SUCCESS; goto d7IdE; d7IdE: } catch (\Exception $re7gC) { $GpXwG['result'] = StrUtil::mbLimit($re7gC->getMessage(), 200); $GpXwG['status'] = RunStatus::FAILED; } $GpXwG['endTime'] = date('Y-m-d H:i:s'); ModelUtil::update('schedule_run', $z8EdL, $GpXwG); if ($I1jol) { $I1jol = 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($pXrNS->cron()); } goto P8Wpu; toOH_: if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] != 'schedule:run') { return; } goto L4Udp; P8Wpu: } }