Skip to content

Commit

Permalink
fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartakusMd committed Nov 25, 2024
1 parent fa9f0f8 commit c95802a
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/EventListener/HandleMonitorStampListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\Stamp\HandledStamp;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Zenstruck\Messenger\Monitor\History\Model\Results;
use Zenstruck\Messenger\Monitor\History\ResultNormalizer;
use Zenstruck\Messenger\Monitor\History\Storage;
use Zenstruck\Messenger\Monitor\Stamp\DisableInputStoreStamp;
use Zenstruck\Messenger\Monitor\Stamp\MonitorStamp;

/**
Expand All @@ -31,6 +33,7 @@ final class HandleMonitorStampListener
public function __construct(
private Storage $storage,
private ResultNormalizer $normalizer,
private SerializerInterface $serializer
) {
}

Expand All @@ -46,7 +49,12 @@ public function handleSuccess(WorkerMessageHandledEvent $event): void

$event->addStamps($stamp->markFinished());

$this->storage->save($event->getEnvelope(), $this->createResults($event->getEnvelope()));
$input = [];
if (!$this->isInputMonitoringDisabled($event->getEnvelope())) {
$input = $this->serializer->encode($event->getEnvelope()->withoutAll(MonitorStamp::class));
}

$this->storage->save($event->getEnvelope(), $input, $this->createResults($event->getEnvelope()));
}

public function handleFailure(WorkerMessageFailedEvent $event): void
Expand All @@ -63,8 +71,14 @@ public function handleFailure(WorkerMessageFailedEvent $event): void

$event->addStamps($stamp->markFinished());

$input = [];
if (!$this->isInputMonitoringDisabled($event->getEnvelope())) {
$input = $this->serializer->encode($event->getEnvelope()->withoutAll(MonitorStamp::class));
}

$this->storage->save(
$event->getEnvelope(),
$input,
$this->createResults($event->getEnvelope(), $throwable instanceof HandlerFailedException ? $throwable : null),
$throwable,
);
Expand Down Expand Up @@ -97,4 +111,21 @@ private function createResults(Envelope $envelope, ?HandlerFailedException $exce

return new Results($results);
}

private function isInputMonitoringDisabled(Envelope $envelope): bool
{
if ($envelope->last(DisableInputStoreStamp::class)) {
return true;
}

$reflection = new \ReflectionClass($envelope->getMessage());
$attributes = [];

while (false !== $reflection && [] === $attributes) {
$attributes = $reflection->getAttributes(DisableInputStoreStamp::class);
$reflection = $reflection->getParentClass();
}

return [] !== $attributes;
}
}

0 comments on commit c95802a

Please sign in to comment.