Skip to content

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          # Scheduler

Related entities in src/Entity/System/:

EntityDescription
Task.phpTask definition (Cron, handler, params)
TaskLog.phpTask 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-scheduler

Scheduling

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 result

Admin 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

Open Source under MIT | Copyright © 2026 Doggy