From b6e75357ca271a0f02048eed9fca2aead6ad4837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Tue, 19 Oct 2021 19:25:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=BA=90=E5=BA=94=E7=94=A8=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=94=AF=E6=8C=81serverless=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Utils.php | 1 + src/Console/Kernel.php | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/Common/Utils.php b/src/Common/Utils.php index 46512de..3b942ac 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 b67e901..33724b3 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); -- Gitee