Skip to content

Commit 50c9c8a

Browse files
committed
[Messenger] fix wrong use of generator returns
And some other minor cleanups
1 parent b82b09e commit 50c9c8a

File tree

11 files changed

+32
-23
lines changed

11 files changed

+32
-23
lines changed

src/Symfony/Component/Messenger/Stamp/SentToFailureTransportStamp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(string $exceptionMessage, string $originalReceiverNa
3232
$this->exceptionMessage = $exceptionMessage;
3333
$this->originalReceiverName = $originalReceiverName;
3434
$this->flattenException = $flattenException;
35-
$this->sentAt = new \DateTime();
35+
$this->sentAt = new \DateTimeImmutable();
3636
}
3737

3838
public function getExceptionMessage(): string
@@ -50,7 +50,7 @@ public function getFlattenException(): ?FlattenException
5050
return $this->flattenException;
5151
}
5252

53-
public function getSentAt(): \DateTime
53+
public function getSentAt(): \DateTimeInterface
5454
{
5555
return $this->sentAt;
5656
}

src/Symfony/Component/Messenger/Tests/Stamp/SentToFailureTransportStampTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public function testGetters()
2828
$this->assertSame('exception message', $stamp->getExceptionMessage());
2929
$this->assertSame('original_receiver', $stamp->getOriginalReceiverName());
3030
$this->assertSame($flattenException, $stamp->getFlattenException());
31-
$this->assertInstanceOf(\DateTime::class, $stamp->getSentAt());
31+
$this->assertInstanceOf(\DateTimeInterface::class, $stamp->getSentAt());
3232
}
3333
}

src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpReceiver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private function getEnvelope(string $queueName): iterable
5757
}
5858

5959
if (null === $amqpEnvelope) {
60-
return [];
60+
return;
6161
}
6262

6363
try {

src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ public function getMessageCount(): int
8484
return ($this->receiver ?? $this->getReceiver())->getMessageCount();
8585
}
8686

87-
private function getReceiver()
87+
private function getReceiver(): AmqpReceiver
8888
{
8989
return $this->receiver = new AmqpReceiver($this->connection, $this->serializer);
9090
}
9191

92-
private function getSender()
92+
private function getSender(): AmqpSender
9393
{
9494
return $this->sender = new AmqpSender($this->connection, $this->serializer);
9595
}

src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function get(): iterable
5454
return [];
5555
}
5656

57-
yield $this->createEnvelopeFromData($doctrineEnvelope);
57+
return [$this->createEnvelopeFromData($doctrineEnvelope)];
5858
}
5959

6060
/**

src/Symfony/Component/Messenger/Transport/Receiver/ListableReceiverInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Messenger\Transport\Receiver;
413

514
use Symfony\Component\Messenger\Envelope;

src/Symfony/Component/Messenger/Transport/Receiver/SingleMessageReceiver.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Messenger\Transport\Receiver;
413

514
use Symfony\Component\Messenger\Envelope;
@@ -32,7 +41,7 @@ public function get(): iterable
3241

3342
$this->hasReceived = true;
3443

35-
yield $this->envelope;
44+
return [$this->envelope];
3645
}
3746

3847
public function ack(Envelope $envelope): void

src/Symfony/Component/Messenger/Transport/RedisExt/RedisReceiver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function get(): iterable
5757
throw $exception;
5858
}
5959

60-
yield $envelope->with(new RedisReceivedStamp($redisEnvelope['id']));
60+
return [$envelope->with(new RedisReceivedStamp($redisEnvelope['id']))];
6161
}
6262

6363
/**

src/Symfony/Component/Messenger/Transport/RedisExt/RedisTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public function setup(): void
7676
$this->connection->setup();
7777
}
7878

79-
private function getReceiver()
79+
private function getReceiver(): RedisReceiver
8080
{
8181
return $this->receiver = new RedisReceiver($this->connection, $this->serializer);
8282
}
8383

84-
private function getSender()
84+
private function getSender(): RedisSender
8585
{
8686
return $this->sender = new RedisSender($this->connection, $this->serializer);
8787
}

src/Symfony/Component/Messenger/Worker.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,11 @@ private function handleMessage(Envelope $envelope, ReceiverInterface $receiver,
136136
$envelope = $throwable->getEnvelope();
137137
}
138138

139-
$shouldRetry = $this->shouldRetry($throwable, $envelope, $retryStrategy);
139+
$shouldRetry = $retryStrategy && $this->shouldRetry($throwable, $envelope, $retryStrategy);
140140

141141
$this->dispatchEvent(new WorkerMessageFailedEvent($envelope, $transportName, $throwable, $shouldRetry));
142142

143143
if ($shouldRetry) {
144-
if (null === $retryStrategy) {
145-
// not logically allowed, but check just in case
146-
throw new LogicException('Retrying is not supported without a retry strategy.');
147-
}
148-
149144
$retryCount = $this->getRetryCount($envelope) + 1;
150145
if (null !== $this->logger) {
151146
$this->logger->error('Retrying {class} - retry #{retryCount}.', $context + ['retryCount' => $retryCount, 'error' => $throwable]);
@@ -194,16 +189,12 @@ private function dispatchEvent($event)
194189
$this->eventDispatcher->dispatch($event);
195190
}
196191

197-
private function shouldRetry(\Throwable $e, Envelope $envelope, ?RetryStrategyInterface $retryStrategy): bool
192+
private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInterface $retryStrategy): bool
198193
{
199194
if ($e instanceof UnrecoverableMessageHandlingException) {
200195
return false;
201196
}
202197

203-
if (null === $retryStrategy) {
204-
return false;
205-
}
206-
207198
$sentStamp = $envelope->last(SentStamp::class);
208199
if (null === $sentStamp) {
209200
if (null !== $this->logger) {

0 commit comments

Comments
 (0)