Skip to content

Commit

Permalink
Catch the exception when consume timeout (#347)
Browse files Browse the repository at this point in the history
* Catch the exception when consume timeout

* Remove the waiter when consume

* Optimize phpdoc

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed Sep 22, 2023
1 parent 35b99ea commit e69f74c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions publish/trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
'concurrent' => [
'limit' => 1000,
],

'consume_timeout' => 600,
],
],
];
12 changes: 7 additions & 5 deletions src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
use Hyperf\Coroutine\Coroutine;
use MySQLReplication\Config\ConfigBuilder;
use MySQLReplication\MySQLReplicationFactory;
use Throwable;

use function Hyperf\Coroutine\wait;
use function Hyperf\Support\make;
use function Hyperf\Tappable\tap;

Expand Down Expand Up @@ -74,7 +74,7 @@ public function __construct(
public function start(): void
{
$callback = function () {
// Health monitor
// Health monitor start
if ($this->healthMonitor) {
$this->healthMonitor->process();
}
Expand All @@ -89,9 +89,7 @@ public function start(): void
// Worker exit
Coroutine::create(function () {
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();

$this->stop();

$this->warning('Consumer stopped.');
});

Expand All @@ -100,7 +98,11 @@ public function start(): void
break;
}

wait(fn () => $replication->consume(), (float) $this->getOption('consume_timeout', 600));
try {
$replication->consume();
} catch (Throwable $e) {
$this->warning((string) $e);
}
}
};

Expand Down

0 comments on commit e69f74c

Please sign in to comment.