Skip to content

[Console][Messenger] cannot suppress retries on RunCommandMessage #60427

Closed
@peterpeppered

Description

@peterpeppered

Symfony version(s) affected

7.2.3

Description

dispatching a RunCommandMessage to an async bus like so :

$this->bus->dispatch(new RunCommandMessage('app:do-stuff', false, false));

I would have expected that throwing an UnrecoverableMessageHandlingException in the command would prevent the messenger from retrying this message, but that does not happen. the exception get wrapped in a RunCommandFailureException and is retried as per normal config. seems that the RunCommandMessageHandler does not currently provide for any other way to prevent retries.

How to reproduce

dispatch a RunCommandMessage() for a command like :

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
    name: 'dummy',
)]
class DummyCommand extends Command
{
    public function __construct()
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        throw new UnrecoverableMessageHandlingException();
    }
}

to your default bus and see it get retried

Possible Solution

No response

Additional Context

see discussion on slack with @kbond :

https://symfony-devs.slack.com/archives/C9PQ75TV3/p1747312075618569

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions