mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 20:58:13 +08:00
Reset event dispatcher after db reconnect.
This commit is contained in:
parent
b060f8fd49
commit
4a771490ae
@ -20,6 +20,7 @@ use Hyperf\DbConnection\Traits\DbConnection;
|
||||
use Hyperf\Pool\Connection as BaseConnection;
|
||||
use Hyperf\Pool\Exception\ConnectionException;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class Connection extends BaseConnection implements ConnectionInterface, DbConnectionInterface
|
||||
{
|
||||
@ -88,6 +89,15 @@ class Connection extends BaseConnection implements ConnectionInterface, DbConnec
|
||||
public function reconnect(): bool
|
||||
{
|
||||
$this->connection = $this->factory->make($this->config);
|
||||
|
||||
// Reset event dispatcher after db reconnect.
|
||||
if ($this->container->has(EventDispatcherInterface::class)) {
|
||||
if ($this->connection instanceof \Hyperf\Database\Connection) {
|
||||
$dispatcher = $this->container->get(EventDispatcherInterface::class);
|
||||
$this->connection->setEventDispatcher($dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
$this->lastUseTime = microtime(true);
|
||||
return true;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ use Hyperf\Pool\Pool;
|
||||
use Hyperf\Pool\PoolOption;
|
||||
use Hyperf\Utils\Arr;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class DbPool extends Pool
|
||||
{
|
||||
@ -64,12 +63,6 @@ class DbPool extends Pool
|
||||
|
||||
protected function createConnection(): ConnectionInterface
|
||||
{
|
||||
$conn = new Connection($this->container, $this, $this->config);
|
||||
if ($this->container->has(EventDispatcherInterface::class)) {
|
||||
$dispatcher = $this->container->get(EventDispatcherInterface::class);
|
||||
$conn->setEventDispatcher($dispatcher);
|
||||
}
|
||||
|
||||
return $conn;
|
||||
return new Connection($this->container, $this, $this->config);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user