From 41bce52883262042e88374d20d33a6df0e635a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 19 Sep 2022 18:39:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DatabasesProviders.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/DatabasesProviders.php b/DatabasesProviders.php index cfd20d5..9afec73 100644 --- a/DatabasesProviders.php +++ b/DatabasesProviders.php @@ -48,12 +48,33 @@ class DatabasesProviders extends Providers return; } $this->provider->on(OnWorkerExit::class, [$this, 'exit'], 9999); + $this->provider->on(OnWorkerStart::class, [$this, 'start']); foreach ($databases as $key => $database) { $application->set($key, $this->_settings($database)); } } + public function start(OnWorkerStart $start) + { + Timer::tick(60000, function () { + $databases = Config::get('databases.connections', []); + if (empty($databases)) { + return; + } + + $min = Config::get('databases.pool.min', 5); + + $connection = Kiri::getDi()->get(PoolConnection::class); + foreach ($databases as $database) { + $connection->flush($database['cds'], $min); + } + + $this->logger->warning("database tick clear."); + }); + } + + /** * @param OnWorkerExit $exit * @return void