Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(
private mixed $id,
private string $class,
private string $serialized,
private ?string $delay = null,
) {
}

Expand All @@ -47,12 +48,18 @@ public function setSerialized(string $serialized): void
$this->serialized = $serialized;
}

public function getDelay(): ?string
{
return $this->delay;
}

public function jsonSerialize(): mixed
{
return [
'id' => $this->id,
'class' => $this->class,
'serialized' => $this->serialized,
'delay' => $this->delay,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

namespace CoreShop\Bundle\MessengerBundle\Messenger;

use Carbon\Carbon;
use Carbon\CarbonInterface;
use CoreShop\Bundle\MessengerBundle\Event\MessageDetailsEvent;
use CoreShop\Bundle\MessengerBundle\Exception\ReceiverNotListableException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Stamp\DelayStamp;
use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp;
use Symfony\Component\Messenger\Transport\Receiver\ListableReceiverInterface;

Expand Down Expand Up @@ -52,6 +55,7 @@ public function listMessages(string $receiverName, int $limit = 10): array
$this->getMessageId($envelope),
$envelope->getMessage()::class,
'<pre>' . print_r($envelope->getMessage(), true) . '</pre>',
$this->getDelayInfo($envelope),
);

/** @var MessageDetailsEvent $event */
Expand All @@ -73,4 +77,19 @@ private function getMessageId(Envelope $envelope): mixed

return $stamp?->getId();
}

private function getDelayInfo(Envelope $envelope): ?string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this method @copilot can try to use

use Carbon\Carbon;
use Carbon\CarbonInterface;

$diff = Carbon::now()->subMilliseconds($delayMs);
return Carbon::now()->diffForHumans(other: $diff, syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

@copilot listen to this man :)

{
/** @var DelayStamp|null $delayStamp */
$delayStamp = $envelope->last(DelayStamp::class);

if (null === $delayStamp) {
return null;
}

$delayMs = $delayStamp->getDelay();
$diff = Carbon::now()->subMilliseconds($delayMs);

return Carbon::now()->diffForHumans(other: $diff, syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ coreshop.messenger.list = Class.create({
rootProperty: 'data'
}
},
fields: ['id', 'class']
fields: ['id', 'class', 'delay']
});

var grid = new Ext.grid.Panel({
Expand All @@ -384,6 +384,10 @@ coreshop.messenger.list = Class.create({
text: t('coreshop_messenger_class'),
flex: 1,
dataIndex: 'class'
}, {
text: t('coreshop_messenger_delay'),
width: 150,
dataIndex: 'delay'
}, {
xtype: 'actioncolumn',
width: 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ coreshop_messenger_failed_messages: 'Fehlgeschlagene Nachrichten'
coreshop_messenger_pending_messages: 'Ausstehende Nachrichten'
coreshop_messenger_receivers: 'Empfänger'
coreshop_messenger_info: 'Details'
coreshop_permission_messenger: 'CoreShop: Messenger'
coreshop_messenger_delay: 'Verzögerung'
coreshop_permission_messenger: 'CoreShop: Messenger'
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ coreshop_messenger_failed_messages: 'Failed Messages'
coreshop_messenger_pending_messages: 'Pending Messages'
coreshop_messenger_receivers: 'Receivers'
coreshop_messenger_info: 'Details'
coreshop_permission_messenger: 'CoreShop: Messenger'
coreshop_messenger_delay: 'Delay'
coreshop_permission_messenger: 'CoreShop: Messenger'