Skip to content

Commit 687a3d6

Browse files
committed
Separate message provider id and description
1 parent b6ae3aa commit 687a3d6

File tree

7 files changed

+31
-11
lines changed

7 files changed

+31
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Messenger/DummyTask.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#[AsCronTask(expression: '0 * * * *', timezone: 'Europe/Berlin', arguments: ['2'], schedule: 'dummy_task', method: 'method2')]
1010
#[AsPeriodicTask(frequency: 5, arguments: [3], schedule: 'dummy_task')]
1111
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', jitter: 60, arguments: ['4'], schedule: 'dummy_task', method: 'method4')]
12+
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', arguments: ['9'], schedule: 'dummy_task', method: 'method5')]
13+
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', arguments: ['9b'], schedule: 'dummy_task', method: 'method5')]
14+
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', arguments: ['named' => '9'], schedule: 'dummy_task', method: 'method5')]
1215
class DummyTask
1316
{
1417
public static array $calls = [];

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SchedulerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function testAutoconfiguredScheduler()
8484
$this->assertCount(779, $calls['__invoke']);
8585
$this->assertSame([['2']], $calls['method2']);
8686
$this->assertSame([['4']], $calls['method4']);
87+
$this->assertSame([['9'], ['9b'], ['named' => '9']], $calls['method5']);
8788
$this->assertSame([['5', 6], ['7', 8]], $calls['attributesOnMethod']);
8889
}
8990

src/Symfony/Component/Scheduler/Command/DebugCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ private static function renderRecurringMessage(RecurringMessage $recurringMessag
114114
return null;
115115
}
116116

117-
return [(string) $trigger, $recurringMessage->getProvider()->getId(), $next];
117+
$provider = $recurringMessage->getProvider();
118+
$description = $provider instanceof \Stringable ? (string) $provider : $provider->getId();
119+
120+
return [(string) $trigger, $description, $next];
118121
}
119122
}

src/Symfony/Component/Scheduler/RecurringMessage.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ public static function trigger(TriggerInterface $trigger, object $message): self
7575
return new self($trigger, $message);
7676
}
7777

78-
$description = '';
79-
try {
80-
$description = $message instanceof \Stringable ? (string) $message : serialize($message);
81-
} catch (\Exception) {
78+
$description = $message::class;
79+
if ($message instanceof \Stringable) {
80+
try {
81+
$description .= "($message)";
82+
} catch (\Exception) {
83+
}
8284
}
83-
$description = sprintf('%s(%s)', $message::class, $description);
8485

85-
return new self($trigger, new StaticMessageProvider([$message], $description));
86+
return new self($trigger, new StaticMessageProvider([$message], hash('crc32c', serialize($message)), $description));
8687
}
8788

8889
public function withJitter(int $maxSeconds = 60): self

src/Symfony/Component/Scheduler/Tests/Trigger/CallbackMessageProviderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ public function testToString()
2929
$this->assertEquals([new \stdClass()], $messageProvider->getMessages($context));
3030
$this->assertSame('', $messageProvider->getId());
3131

32-
$messageProvider = new CallbackMessageProvider(fn () => yield new \stdClass(), 'foo');
32+
$messageProvider = new CallbackMessageProvider(fn () => yield new \stdClass(), 'foo', 'bar');
3333
$this->assertInstanceOf(\Generator::class, $messageProvider->getMessages($context));
3434
$this->assertSame('foo', $messageProvider->getId());
35+
$this->assertSame('bar', (string) $messageProvider);
3536
}
3637
}

src/Symfony/Component/Scheduler/Trigger/CallbackMessageProvider.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Symfony\Component\Scheduler\Generator\MessageContext;
1515

16-
final class CallbackMessageProvider implements MessageProviderInterface
16+
final class CallbackMessageProvider implements MessageProviderInterface, \Stringable
1717
{
1818
private \Closure $callback;
1919

2020
/**
2121
* @param callable(MessageContext): iterable<object> $callback
2222
*/
23-
public function __construct(callable $callback, private string $id = '')
23+
public function __construct(callable $callback, private string $id = '', private string $description = '')
2424
{
2525
$this->callback = $callback(...);
2626
}
@@ -34,4 +34,9 @@ public function getId(): string
3434
{
3535
return $this->id;
3636
}
37+
38+
public function __toString(): string
39+
{
40+
return $this->description ?: $this->id;
41+
}
3742
}

src/Symfony/Component/Scheduler/Trigger/StaticMessageProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
use Symfony\Component\Scheduler\Generator\MessageContext;
1515

16-
final class StaticMessageProvider implements MessageProviderInterface
16+
final class StaticMessageProvider implements MessageProviderInterface, \Stringable
1717
{
1818
/**
1919
* @param array<object> $messages
2020
*/
2121
public function __construct(
2222
private array $messages,
2323
private string $id = '',
24+
private string $description = '',
2425
) {
2526
}
2627

@@ -33,4 +34,9 @@ public function getId(): string
3334
{
3435
return $this->id;
3536
}
37+
38+
public function __toString(): string
39+
{
40+
return $this->description ?: $this->id;
41+
}
3642
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy