Skip to content
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

[Scheduler] Fix messenger receiver with no alias #53817

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger;

use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;

#[AsPeriodicTask(frequency: 5, schedule: 'custom_receiver')]
class DummyTaskWithCustomReceiver
{
public function __invoke()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public function testAutoconfiguredScheduler()
$this->assertSame([['5', 6], ['7', 8]], $calls['attributesOnMethod']);
}

public function testSchedulerWithCustomTransport()
{
$container = self::getContainer();
$container->set('clock', new MockClock('2023-10-26T08:59:59Z'));

$this->assertTrue($container->get('receivers')->has('scheduler_custom_receiver'));
$this->assertSame($container->get('scheduler_custom_receiver'), $container->get('receivers')->get('scheduler_custom_receiver'));
}

protected static function createKernel(array $options = []): KernelInterface
{
return parent::createKernel(['test_case' => 'Scheduler'] + $options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ services:
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyTask:
autoconfigure: true

Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyTaskWithCustomReceiver:
autoconfigure: true

clock:
synthetic: true

receivers:
public: true
alias: 'messenger.receiver_locator'

scheduler_custom_receiver:
public: true
class: Symfony\Component\Messenger\Transport\TransportInterface
factory: [ '@messenger.transport_factory', 'createTransport' ]
arguments:
- 'schedule://custom_receiver'
- { transport_name: 'scheduler_custom_receiver' }
- !service
class: Symfony\Component\Messenger\Transport\Serialization\Serializer
tags:
- { name: 'messenger.receiver' }
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"symfony/notifier": "^5.4|^6.0|^7.0",
"symfony/process": "^5.4|^6.0|^7.0",
"symfony/rate-limiter": "^5.4|^6.0|^7.0",
"symfony/scheduler": "^6.4.3|^7.0.3",
"symfony/scheduler": "^6.4.4|^7.0.4",
"symfony/security-bundle": "^5.4|^6.0|^7.0",
"symfony/semaphore": "^5.4|^6.0|^7.0",
"symfony/serializer": "^6.4|^7.0",
Expand Down Expand Up @@ -93,7 +93,7 @@
"symfony/mime": "<6.4",
"symfony/property-info": "<5.4",
"symfony/property-access": "<5.4",
"symfony/scheduler": "<6.4.3|>=7.0.0,<7.0.3",
"symfony/scheduler": "<6.4.4|>=7.0.0,<7.0.4",
"symfony/serializer": "<6.4",
"symfony/security-csrf": "<5.4",
"symfony/security-core": "<5.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public function process(ContainerBuilder $container): void
}

$receivers = [];
foreach ($container->findTaggedServiceIds('messenger.receiver') as $tags) {
$receivers[$tags[0]['alias']] = true;
foreach ($container->findTaggedServiceIds('messenger.receiver') as $serviceId => $tags) {
$receivers[$serviceId] = true;
if (isset($tags[0]['alias'])) {
$receivers[$tags[0]['alias']] = true;
}
}

$scheduleProviderIds = [];
Expand Down