Skip to content

[Scheduler] add schedule name to ScheduledStamp #49864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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 @@ -18,4 +18,7 @@
*/
final class ScheduledStamp implements NonSendableStampInterface
{
public function __construct(public readonly string $scheduleName)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ class SchedulerTransport implements TransportInterface
{
public function __construct(
private readonly MessageGeneratorInterface $messageGenerator,
private readonly string $name,
) {
}

public function get(): iterable
{
foreach ($this->messageGenerator->getMessages() as $message) {
yield Envelope::wrap($message, [new ScheduledStamp()]);
yield Envelope::wrap($message, [new ScheduledStamp($this->name)]);
Copy link
Member

Choose a reason for hiding this comment

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

but that doesn't work: the name is something that belongs to a schedule, not to the transport. The generated messages can come from many schedules.

Copy link
Member Author

Choose a reason for hiding this comment

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

Each schedule has its own transport though.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function createTransport(string $dsn, array $options, SerializerInterface
$schedule = $this->scheduleProviders->get($scheduleName)->getSchedule();
$checkpoint = new Checkpoint('scheduler_checkpoint_'.$scheduleName, $schedule->getLock(), $schedule->getState());

return new SchedulerTransport(new MessageGenerator($schedule, $checkpoint, $this->clock));
return new SchedulerTransport(new MessageGenerator($schedule, $checkpoint, $this->clock), $scheduleName);
}

public function supports(string $dsn, array $options): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function testCreateTransport()
$defaultRecurringMessage = RecurringMessage::trigger($trigger, (object) ['id' => 'default']);
$customRecurringMessage = RecurringMessage::trigger($trigger, (object) ['id' => 'custom']);

$default = new SchedulerTransport(new MessageGenerator((new SomeScheduleProvider([$defaultRecurringMessage]))->getSchedule(), 'default', $clock));
$custom = new SchedulerTransport(new MessageGenerator((new SomeScheduleProvider([$customRecurringMessage]))->getSchedule(), 'custom', $clock));
$default = new SchedulerTransport(new MessageGenerator((new SomeScheduleProvider([$defaultRecurringMessage]))->getSchedule(), 'default', $clock), 'default');
$custom = new SchedulerTransport(new MessageGenerator((new SomeScheduleProvider([$customRecurringMessage]))->getSchedule(), 'custom', $clock), 'custom');

$factory = new SchedulerTransportFactory(
new Container([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function testGetFromIterator()
$generator = $this->createConfiguredMock(MessageGeneratorInterface::class, [
'getMessages' => $messages,
]);
$transport = new SchedulerTransport($generator);
$transport = new SchedulerTransport($generator, 'default');

foreach ($transport->get() as $envelope) {
$this->assertInstanceOf(Envelope::class, $envelope);
$this->assertNotNull($envelope->last(ScheduledStamp::class));
$this->assertSame('default', $envelope->last(ScheduledStamp::class)->scheduleName);
$this->assertSame(array_shift($messages), $envelope->getMessage());
}

Expand All @@ -42,23 +42,23 @@ public function testGetFromIterator()

public function testAckIgnored()
{
$transport = new SchedulerTransport($this->createMock(MessageGeneratorInterface::class));
$transport = new SchedulerTransport($this->createMock(MessageGeneratorInterface::class), 'default');

$this->expectNotToPerformAssertions();
$transport->ack(new Envelope(new \stdClass()));
}

public function testRejectException()
{
$transport = new SchedulerTransport($this->createMock(MessageGeneratorInterface::class));
$transport = new SchedulerTransport($this->createMock(MessageGeneratorInterface::class), 'default');

$this->expectException(LogicException::class);
$transport->reject(new Envelope(new \stdClass()));
}

public function testSendException()
{
$transport = new SchedulerTransport($this->createMock(MessageGeneratorInterface::class));
$transport = new SchedulerTransport($this->createMock(MessageGeneratorInterface::class), 'default');

$this->expectException(LogicException::class);
$transport->send(new Envelope(new \stdClass()));
Expand Down