Skip to content

Commit 1987c74

Browse files
authored
Merge pull request #60 from 21TORR/task-manager-queue
Add docs for DispatchAfterRunTask
2 parents 7dc02ac + b990c61 commit 1987c74

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: "Task Manager: DispatchAfterRunTask"
3+
authors: [jannik]
4+
tags: [task-manager]
5+
---
6+
7+
The task manager is now able [to redispatch messages], that should be used in the Scheduler, for example.
8+
9+
[to redispatch messages]: /docs/php/symfony/task-manager/#queueing-tasks-after-the-current-run

docs/php/symfony/task-manager/index.mdx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,44 @@ bin/console task-manager:queue task-id-1 task-id-2
192192
```
193193

194194

195+
### Queueing Tasks After the Current Run
196+
197+
You can also queue tasks after the current run. This is handy when dispatching tasks in a scheduler. The scheduler
198+
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
199+
to use the priority system.
200+
201+
```php
202+
use Symfony\Component\Scheduler\Attribute\AsSchedule;
203+
use Symfony\Component\Scheduler\ScheduleProviderInterface;
204+
use Symfony\Component\Scheduler\Schedule;
205+
use Torr\TaskManager\Task\DispatchAfterRunTask\DispatchAfterRunTask;
206+
207+
#[AsSchedule]
208+
class AppSchedule implements ScheduleProviderInterface
209+
{
210+
public function getSchedule() : Schedule
211+
{
212+
return new Schedule()
213+
// ...
214+
->add(RecurringMessage::cron(
215+
"*/5 * * * *",
216+
// we want to redispatch the task in the scheduler
217+
new DispatchAfterRunTask(
218+
new DownloadExternalFilesTask(),
219+
),
220+
));
221+
}
222+
}
223+
```
224+
225+
226+
:::warning
227+
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).
228+
229+
We want to keep using the default queue, so we have our own task for that.
230+
:::
231+
232+
195233
## Task Handlers
196234

197235
As this bundle builds on top of Symfony messages, you define your task handler as message handler:
@@ -288,4 +326,4 @@ bin/console task-manager:debug
288326
[Supervisor]: https://symfony.com/doc/current/messenger.html#supervisor-configuration
289327
[Symfony Messenger]: https://symfony.com/doc/current/messenger.html
290328
[systemd]: https://symfony.com/doc/current/messenger.html#systemd-configuration
291-
329+
[`RedispatchMessage`]: https://symfony.com/doc/current/messenger.html#redispatching-a-message

0 commit comments

Comments
 (0)