Skip to content

Commit

Permalink
Fixed first heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxi committed Aug 28, 2023
1 parent 89ce747 commit 9543e81
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Consumer/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,21 @@ protected function heartbeat(): void
}
}

protected function getLastHeartbeatTime(): float
{
return $this->lastHeartbeatTime > 0 ? $this->lastHeartbeatTime : microtime(true);
}

protected function setLastHeartbeatTime(float $lastHeartbeatTime): void
{
$this->lastHeartbeatTime = $lastHeartbeatTime;
}

protected function checkBeartbeat(): void
{
$time = microtime(true);
if ($time - $this->lastHeartbeatTime >= $this->config->getGroupHeartbeat()) {
$this->lastHeartbeatTime = $time;
if ($time - $this->getLastHeartbeatTime() >= $this->config->getGroupHeartbeat()) {
$this->setLastHeartbeatTime($time);
$this->heartbeat();
}
}
Expand Down

0 comments on commit 9543e81

Please sign in to comment.