This commit is contained in:
2023-04-04 14:29:33 +08:00
parent e55eb19768
commit 5064e5d683
+10 -7
View File
@@ -288,8 +288,8 @@ class PDO implements StopHeartbeatCheck
$container = Kiri::getDi()->get(WorkerStatus::class); $container = Kiri::getDi()->get(WorkerStatus::class);
if (!$result || $container->is(StatusEnum::EXIT)) { if (!$result || $container->is(StatusEnum::EXIT)) {
$this->pdo = null; $this->pdo = null;
$result = Timer::clear($this->_timerId); // $result = Timer::clear($this->_timerId);
$this->_timerId = -1; // $this->_timerId = -1;
} }
return $result; return $result;
} }
@@ -320,10 +320,10 @@ class PDO implements StopHeartbeatCheck
public function execute(string $sql, array $params = []): int public function execute(string $sql, array $params = []): int
{ {
$pdo = $this->_pdo(); $pdo = $this->_pdo();
if ($this->_timerId === -1) { // if ($this->_timerId === -1) {
$this->_timerId = Timer::tick(6000, [$this, 'check']); // $this->_timerId = Timer::tick(6000, [$this, 'check']);
} // }
$this->_last = time(); // $this->_last = time();
if (!(($prepare = $pdo->prepare($sql)) instanceof PDOStatement)) { if (!(($prepare = $pdo->prepare($sql)) instanceof PDOStatement)) {
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE); throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
} }
@@ -366,6 +366,9 @@ class PDO implements StopHeartbeatCheck
{ {
$this->group->add(); $this->group->add();
Coroutine::create(function () { Coroutine::create(function () {
\Co\defer(function () {
$this->group->done();
});
$link = new \PDO('mysql:dbname=' . $this->dbname . ';host=' . $this->cds, $this->username, $this->password, [ $link = new \PDO('mysql:dbname=' . $this->dbname . ';host=' . $this->cds, $this->username, $this->password, [
\PDO::ATTR_EMULATE_PREPARES => false, \PDO::ATTR_EMULATE_PREPARES => false,
\PDO::ATTR_CASE => \PDO::CASE_NATURAL, \PDO::ATTR_CASE => \PDO::CASE_NATURAL,
@@ -385,7 +388,7 @@ class PDO implements StopHeartbeatCheck
$this->pdo = $link; $this->pdo = $link;
}); });
$this->group->done(); $this->group->wait();
return $this->pdo; return $this->pdo;
} }