Skip to content

Commit

Permalink
add receivedTimestamp to message
Browse files Browse the repository at this point in the history
  • Loading branch information
basert committed Nov 11, 2024
1 parent cf3df90 commit d8e745f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Queue/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Message
protected string $queue;
protected int $timestamp;
protected array $payload;
protected float $receivedTimestamp;

public function __construct(array $array = [])
{
Expand All @@ -19,6 +20,7 @@ public function __construct(array $array = [])
$this->queue = $array['queue'];
$this->timestamp = $array['timestamp'];
$this->payload = $array['payload'] ?? [];
$this->receivedTimestamp = (float)$array['receivedTimestamp'] ?? 0.;
}

public function setPid(string $pid): self
Expand Down Expand Up @@ -69,6 +71,17 @@ public function getPayload(): array
return $this->payload;
}

/**
* Timestamp recorded when this message was received by the server.
* The delta between `$receivedTimestamp` and `$timestamp` is the amount of time the message was waiting in the queue.
*
* @return float
*/
public function getReceivedTimestamp(): float
{
return $this->receivedTimestamp;
}

public function asArray(): array
{
return [
Expand Down
1 change: 1 addition & 0 deletions src/Queue/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public function start(): self
}

$nextMessage['timestamp'] = (int)$nextMessage['timestamp'];
$nextMessage['receivedTimestamp'] = microtime(true);

$message = new Message($nextMessage);

Expand Down

0 comments on commit d8e745f

Please sign in to comment.