Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions blog/2025-11-07-task-manager-redispatch.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Task Manager: DispatchAfterRunTask"
authors: [jannik]
tags: [task-manager]
---

The task manager is now able [to redispatch messages], that should be used in the Scheduler, for example.

[to redispatch messages]: /docs/php/symfony/task-manager/#queueing-tasks-after-the-current-run
40 changes: 39 additions & 1 deletion docs/php/symfony/task-manager/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,44 @@ bin/console task-manager:queue task-id-1 task-id-2
```


### Queueing Tasks After the Current Run

You can also queue tasks after the current run. This is handy when dispatching tasks in a scheduler. The scheduler
starts working on these tasks right away, but in nearly all cases you want to have these tasks in their regular queues, to be able
to use the priority system.

```php
use Symfony\Component\Scheduler\Attribute\AsSchedule;
use Symfony\Component\Scheduler\ScheduleProviderInterface;
use Symfony\Component\Scheduler\Schedule;
use Torr\TaskManager\Task\DispatchAfterRunTask\DispatchAfterRunTask;

#[AsSchedule]
class AppSchedule implements ScheduleProviderInterface
{
public function getSchedule() : Schedule
{
return new Schedule()
// ...
->add(RecurringMessage::cron(
"*/5 * * * *",
// we want to redispatch the task in the scheduler
new DispatchAfterRunTask(
new DownloadExternalFilesTask(),
),
));
}
}
```


:::warning
Symfony has a similar feature with the [`RedispatchMessage`], however in their implementation you need to explicitly specify the queue the task should go into (otherwise it will get dropped).

We want to keep using the default queue, so we have our own task for that.
:::


## Task Handlers

As this bundle builds on top of Symfony messages, you define your task handler as message handler:
Expand Down Expand Up @@ -288,4 +326,4 @@ bin/console task-manager:debug
[Supervisor]: https://symfony.com/doc/current/messenger.html#supervisor-configuration
[Symfony Messenger]: https://symfony.com/doc/current/messenger.html
[systemd]: https://symfony.com/doc/current/messenger.html#systemd-configuration

[`RedispatchMessage`]: https://symfony.com/doc/current/messenger.html#redispatching-a-message