From b983a6cb006652562b1e1f9107ef504ba43e1371 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Sun, 10 Nov 2024 02:11:31 -0500 Subject: [PATCH] feat!: add wait/handle time to `ProcessedMessage` --- config/doctrine/mapping/ProcessedMessage.orm.xml | 2 ++ src/History/Model/ProcessedMessage.php | 10 +++++++--- src/History/Storage/ORMStorage.php | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/config/doctrine/mapping/ProcessedMessage.orm.xml b/config/doctrine/mapping/ProcessedMessage.orm.xml index f2408fe..a03e201 100644 --- a/config/doctrine/mapping/ProcessedMessage.orm.xml +++ b/config/doctrine/mapping/ProcessedMessage.orm.xml @@ -11,6 +11,8 @@ + + diff --git a/src/History/Model/ProcessedMessage.php b/src/History/Model/ProcessedMessage.php index 9d93ac9..14bdfd6 100644 --- a/src/History/Model/ProcessedMessage.php +++ b/src/History/Model/ProcessedMessage.php @@ -37,6 +37,8 @@ abstract class ProcessedMessage private int $memoryUsage; private string $transport; private ?string $tags; + private int $waitTime; + private int $handleTime; /** @var class-string<\Throwable> */ private ?string $failureType = null; @@ -61,6 +63,8 @@ public function __construct(Envelope $envelope, Results $results, ?\Throwable $e $this->transport = $monitorStamp->transport(); $this->tags = $tags->count() ? (string) $tags : null; $this->results = $results; + $this->waitTime = \max(0, $this->receivedAt->getTimestamp() - $this->dispatchedAt->getTimestamp()); + $this->handleTime = \max(0, $this->finishedAt->getTimestamp() - $this->receivedAt->getTimestamp()); if ($retryStamp = $envelope->last(RedeliveryStamp::class)) { $this->attempt += $retryStamp->getRetryCount(); @@ -146,17 +150,17 @@ final public function isFailure(): bool final public function timeInQueue(): int { - return \max(0, $this->receivedAt->getTimestamp() - $this->dispatchedAt->getTimestamp()); + return $this->waitTime; } final public function timeToHandle(): int { - return \max(0, $this->finishedAt->getTimestamp() - $this->receivedAt->getTimestamp()); + return $this->handleTime; } final public function timeToProcess(): int { - return \max(0, $this->finishedAt->getTimestamp() - $this->dispatchedAt->getTimestamp()); + return $this->waitTime + $this->handleTime; } final public function memoryUsage(): Bytes diff --git a/src/History/Storage/ORMStorage.php b/src/History/Storage/ORMStorage.php index 347a931..92c02e2 100644 --- a/src/History/Storage/ORMStorage.php +++ b/src/History/Storage/ORMStorage.php @@ -92,7 +92,7 @@ public function averageWaitTime(Specification $specification): ?float { $qb = $this ->queryBuilderFor($specification, false) - ->select('AVG(m.receivedAt - m.dispatchedAt)') + ->select('AVG(m.waitTime)') ; return (new EntityResult($qb))->asFloat()->first(); @@ -102,7 +102,7 @@ public function averageHandlingTime(Specification $specification): ?float { $qb = $this ->queryBuilderFor($specification, false) - ->select('AVG(m.finishedAt - m.receivedAt)') + ->select('AVG(m.handleTime)') ; return (new EntityResult($qb))->asFloat()->first();