Skip to content

Commit

Permalink
Optimize logging and fix connection information in Consumer (#709)
Browse files Browse the repository at this point in the history
* Optimize logging and fix connection information in Consumer

* Optimize logging and handle connection loss in Consumer.php

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia authored Sep 5, 2024
1 parent 767bd0a commit 406f903
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,20 @@ public function start(): void
Coroutine::create(function () use ($context) {
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
$this->stop();
$this->logger?->warning('[{connection}] Consumer stopped.', $context);
$this->logger?->warning('[{connection}] Consumer exit.', $context);
});

while (1) {
if ($this->isStopped()) {
$this->logger?->warning('[{connection}] Consumer stopped.', $context);
break;
}

try {
$replication->consume();
} catch (SocketException $e) {
// todo: reconnect
$this->logger?->debug('[{connection}] Connection lost, reconnected.', $context);
$this->stop();
$this->logger?->warning('[{connection}] Connection lost, will retry later.', $context);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/Monitor/HealthMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class HealthMonitor
{
protected BinLogCurrent $binLogCurrent;
protected ?BinLogCurrent $binLogCurrent = null;

protected int $monitorInterval = 10;

Expand Down

0 comments on commit 406f903

Please sign in to comment.