From e0fc63d78c9f1dbbd4a6d0273e5649b1f43948fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 23 Jun 2022 00:45:43 +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 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/DatabasesProviders.php b/DatabasesProviders.php index d94ce04..e80d9b4 100644 --- a/DatabasesProviders.php +++ b/DatabasesProviders.php @@ -53,21 +53,26 @@ class DatabasesProviders extends Providers $application->set($key, $this->_settings($database)); } } - - + + /** * @param OnWorkerExit $exit * @return void + * @throws ConfigException + * @throws Exception */ public function exit(OnWorkerExit $exit): void { - $id = (int)Kiri\Context::getContext('db.loop.id'); - if (!empty($id)) { - Timer::clear($id); + Timer::clearAll(); + $databases = Config::get('databases.connections', []); + if (!empty($databases)) { + $connection = Kiri::getDi()->get(PoolConnection::class); + foreach ($databases as $database) { + $connection->disconnect($database['cds']); + } } } - /** * @param $name * @return Connection @@ -85,7 +90,7 @@ class DatabasesProviders extends Providers */ public function check(OnTaskerStart|OnWorkerStart $start): void { - $timerTick = Timer::tick(50 * 1000, static function () use ($start) { + Timer::tick(50 * 1000, static function () use ($start) { $databases = Config::get('databases.connections', []); $valid = 0; $count = 0; @@ -114,7 +119,6 @@ class DatabasesProviders extends Providers } $logger->alert(sprintf('Worker %d db client has %d, valid %d', $start->workerId, $count, $valid)); }); - Kiri\Context::setContext('db.loop.id', $timerTick); }