Scheduler
Doggy includes a built-in task scheduling system based on custom TaskScheduler + Symfony Messenger, supporting distributed execution and multiple task types.
Overview
The scheduler system lives in src/Service/Task/:
src/Service/Task/
├── TaskHandlerInterface.php # Task handler interface
├── TaskHandlerLocator.php # Handler locator
└── TaskScheduler.php # SchedulerRelated entities in src/Entity/System/:
| Entity | Description |
|---|---|
Task.php | Task definition (Cron, handler, params) |
TaskLog.php | Task execution log |
Creating a Task
1. Implement a Task Handler
php
namespace App\Task;
use App\Service\Task\TaskHandlerInterface;
class ActivateAccountByHireDateTask implements TaskHandlerInterface
{
public function handle(array $params = []): void
{
// Execute business logic
}
}Example: src/Task/ActivateAccountByHireDateTask.php
2. Register the Task
Register via command or database:
bash
php bin/console app:run-schedulerScheduling
The TaskScheduler works as follows:
- Reads Task configurations from the database
- Parses Cron expressions
- Locates handlers via
TaskHandlerLocator - Dispatches execution via Symfony Messenger (
RunTaskMessage+RunTaskMessageHandler) - Records results in
TaskLog
Message Architecture
TaskScheduler → Dispatch RunTaskMessage
↓
Messenger (Doctrine Transport)
↓
RunTaskMessageHandler → TaskHandlerInterface::handle()
↓
TaskLog records execution resultAdmin Interface
Controller: App\Controller\Admin\TaskController
Template: templates/admin/task/index.html.twig
- View task list
- View execution logs
- Manually trigger tasks
Features
- Cron expression scheduling
- Asynchronous execution (Messenger queue)
- Execution status tracking (TaskLog)
- Retry mechanism
- Extensible handler interface