Skip to content

Commit

Permalink
feat!: add wait/handle time to ProcessedMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Nov 10, 2024
1 parent 53f7064 commit b983a6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/doctrine/mapping/ProcessedMessage.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<field name="dispatchedAt" column="dispatched_at" type="datetime_immutable" />
<field name="receivedAt" column="received_at" type="datetime_immutable" />
<field name="finishedAt" column="finished_at" type="datetime_immutable" />
<field name="waitTime" column="wait_time" type="integer" />
<field name="handleTime" column="handle_time" type="integer" />
<field name="memoryUsage" column="memory_usage" type="integer" />
<field name="transport" column="transport" />
<field name="tags" column="tags" nullable="true" />
Expand Down
10 changes: 7 additions & 3 deletions src/History/Model/ProcessedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/History/Storage/ORMStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit b983a6c

Please sign in to comment.