diff --git a/src/Common/Utils.php b/src/Common/Utils.php index 46512de96636b407c41fb0e7f440f1d4448bedd2..3b942ac05785f8d9022514082098ad0d985963d4 100644 --- a/src/Common/Utils.php +++ b/src/Common/Utils.php @@ -187,6 +187,7 @@ class Utils } header('Content-Type:application/json; charset=utf-8', true, 200); header('Dzq-CostTime:' . ((microtime(true) - DISCUZ_START) * 1000) . 'ms'); + !empty(getenv('KUBERNETES_OAC_HOST')) && DzqCache::set(CacheKey::OAC_REQUEST_TIME, time()); exit(json_encode($ret, 256)); } diff --git a/src/Console/Kernel.php b/src/Console/Kernel.php index b67e9015015673055dc6c05c7653f99cd670178b..33724b34bac939b3c9a88d2ebf609914842befff 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -18,6 +18,8 @@ namespace Discuz\Console; +use App\Common\CacheKey; +use Discuz\Base\DzqCache; use Discuz\Base\DzqKernel; use Discuz\Common\Utils; use Discuz\Console\Event\Configuring; @@ -62,6 +64,12 @@ class Kernel extends SiteApp implements KernelContract */ protected function defineConsoleSchedule() { + + $lastReq = DzqCache::get(CacheKey::OAC_REQUEST_TIME); + if (!empty($lastReq)) { + //超过30分钟,关闭定时脚本 + if ((time() - $lastReq) / 60.0 > 30) return; + } $this->app->singleton(Schedule::class, function ($app) { return tap(new Schedule($this->scheduleTimezone()), function (Schedule &$schedule) use ($app) { $this->schedule($schedule);