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/2026-02-23-task-manager-scheduler.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Task Manager: Scheduler"
authors: [jannik]
tags: [task-manager]
---

The task manager now has an [integrated scheduler][1], that you should use instead of Symfony's scheduler.

[1]: /docs/php/symfony/task-manager/#schedules
46 changes: 46 additions & 0 deletions docs/php/symfony/task-manager/index.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {LinkList} from "../../../../src/components/Link/LinkList";
import {AddedBadge} from "../../../../src/components/AddedBadge";

# Task Manager

Expand Down Expand Up @@ -274,6 +275,51 @@ While not explicitly `->finish()`ed tasks will be handled properly, you should a
:::


## Schedules

<AddedBadge package="21torr/task-manager" version="3.2.0" />

The task manager also supports scheduling tasks like the Symfony scheduler.

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

#[AsSchedule]
class MySchedule implements ScheduleProviderInterface
{
public function __construct(
private TaskScheduler $taskScheduler,
) {}

public function getSchedule() : Schedule
{
return $this->taskScheduler->createSchedule()
->cron("* * * * *", new Task1())
->every("10 seconds", new Task2())
->getSchedule();
}
}
```

This automatically registers these tasks for the next regular messenger work run, so they are not being worked on right away.


### `DispatchAfterRunTask`

If you want to dispatch tasks after the current run, you can use the `DispatchAfterRunTask`.
This is especially useful for tasks that are scheduled via the scheduler, as the scheduler normally starts working on these tasks right away.
This way the priority system is circumvented.

Normally, this is not desired, so you should use this helper task.

:::info
The `TaskScheduler` automatically wraps all provided tasks in `DispatchAfterRunTask`.
:::


## Task Log

The `TaskDirector` and `RunDirector` automatically log the output of your tasks, whether they succeeded and some metadata. This includes the task object itself, so it must be serializable.
Expand Down