From cfd67d81741c7a14c234f64919a7aebb6efecae8 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 4 Mar 2026 10:28:35 +1100 Subject: [PATCH] Refactor agent ingest timer handling --- agent/build/agent.phar | Bin 850903 -> 850661 bytes agent/build/signature.txt | 2 +- agent/src/Ingest.php | 30 ++++++++++++++---------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/agent/build/agent.phar b/agent/build/agent.phar index 02279700535fa457d258c61310870538b1a0344f..d6507e19fbbcd8a087976e5ccbd400e105605fc2 100755 GIT binary patch delta 389 zcmccq-T3KO;|)Es0b(;sf;60@$x|Gdu-^2A^ zW#38)*aW(9xm>;SWm=HjinzrWJ8j-G3!Zx#Evz*6{qcgy+2PGgSr`}?+?{-#0Lspo Av;Y7A delta 556 zcmaF*)%f~%;|CngI|c7aws+OkR+{A%aDJ z$n=k|xFx4g_{z*R-5`sFb@Kd>db-;vIXNNJ8r}1g7l!7FV)GBw$?~r3+>`CX7ENyu zX6452abVcUO-^{nK3yS=g$)!wILw>x%_=%QU^@^0X8!Otf$3JeI87$U_bD`=%xFKE z!3e}mK+FupEI`Z(#B4y!4#XTl%n8I?K+L`UWCqWbi5{)9W44RzbI-`R=IY|0big>Z z?S#n2buffer->isNotEmpty() && $this->buffer->willExceedThresholdWith($payload)) { - if ($this->sendBufferAfterDelayTimer !== null) { - $this->loop->cancelTimer($this->sendBufferAfterDelayTimer); - - $this->sendBufferAfterDelayTimer = null; - } + $this->cancelDigestDelay(); $this->digest(); } @@ -71,16 +67,12 @@ public function write(string $payload): void $this->buffer->write($payload); if ($this->buffer->reachedThreshold()) { - if ($this->sendBufferAfterDelayTimer !== null) { - $this->loop->cancelTimer($this->sendBufferAfterDelayTimer); - - $this->sendBufferAfterDelayTimer = null; - } + $this->cancelDigestDelay(); $this->digest(); } elseif ($this->buffer->isNotEmpty()) { - $this->sendBufferAfterDelayTimer ??= $this->loop->addTimer($this->maxBufferDurationInSeconds, function () { - $this->sendBufferAfterDelayTimer = null; + $this->digestDelayTimer ??= $this->loop->addTimer($this->maxBufferDurationInSeconds, function () { + $this->digestDelayTimer = null; $this->digest(); }); @@ -92,9 +84,7 @@ public function write(string $payload): void */ public function forceDigest(): PromiseInterface { - if ($this->sendBufferAfterDelayTimer !== null) { - $this->loop->cancelTimer($this->sendBufferAfterDelayTimer); - } + $this->cancelDigestDelay(); if ($this->buffer->isNotEmpty()) { $this->digest(); @@ -233,4 +223,12 @@ private function parseResponse(ResponseInterface $response): array $refreshIn, ]; } + + private function cancelDigestDelay(): void + { + if ($this->digestDelayTimer !== null) { + $this->loop->cancelTimer($this->digestDelayTimer); + $this->digestDelayTimer = null; + } + } }