Search by

badpixxel / tasking-bundle

BadPixxel

Advanced Tasking Bundle for Symfony Applications (100% PHP)

Package info

gitlab.com/badpixxel-public/Tasking-Bundle

Homepage

Issues

Type:symfony-bundle

pkg:composer/badpixxel/tasking-bundle

Statistics

Installs: 2 450

Dependents: 0

Suggesters: 0

Stars: 0

3.0 2026-11-20 18:22 UTC

This package is auto-updated.

Last update: 2026-11-24 11:58:26 UTC


README

Advanced Tasking Manager for Symfony. 100% Php with high concurrency management.

Key features

  • Background tasking: create jobs to be run by workers (Symfony commands)
  • 100% PHP, works on any Linux Server with PHP7.2+
  • High concurrency management: use jobs token to ensure task is executed by a single process.
  • Multi-server compatible: tokens are stored in a central SQL Table.
  • Optimized memory footprint: create a dedicated Symfony environnement to reduce memory impacts.

Total Downloads Latest Stable Version

Installation

Step 1 - Requirements and Installing the bundle

The first step is to tell composer that you want to download Tasking-Bundle which can be achieved by typing the following at the command prompt:

composer require badpixxel/tasking-bundle

Step 2 - Enable the bundle in your kernel

The bundle must be added to your AppKernel.

**Step usually not necessary in Symfony Flex.

// app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        new \BadPixxel\Tasking\BadpixxelTaskingBundle(),
        // ...
    );
}

Create Your First Job

Background jobs must extend BadPixxel\Tasking\Model\AbstractJob.

use BadPixxel\Tasking\Model\AbstractJob;

class MyJob extends AbstractJob
{
    /** @return bool */
    public function execute() : bool
    {
        // Execute your background operations
        // ...
        return true;
    }
}

Job Token may be defined multiple way:

use BadPixxel\Tasking\Model\AbstractJob;

class MyJob extends AbstractJob
{
    /** You can set it directly by overriding this constant */
    protected $token = "";

    /**
     * Or by writing an array of parameters to setToken()
     * @param array $parameters 
     * @return self
     */
    public function setup(array $parameters): self
    {
        //====================================================================//
        // Setup Job Token
        $this->setToken($parameters);

        return $this;
    }
}

Available Job Types

There are few predefined abstract job types, for different kinds of tasks:

  • BadPixxel\Tasking\Model\AbstractJob: a single simple task, executed once by job class.
  • BadPixxel\Tasking\Model\AbstractServiceJob: execute a Symfony service action with given parameters
  • BadPixxel\Tasking\Model\AbstractStaticJob: a simple task, executed & repeated every XX minutes.
  • BadPixxel\Tasking\Model\AbstractBatchJob: step-by-step, execute multiple tasks inside a single job.

Long Running Tasks

A running task is considered as faulty, and replayed, when it was not seen alive for longer than the tasks error delay. Its worker is considered as dead when it stays silent longer than watchdog_delay + refresh_delay.

Any code running inside a task (job, service, listener) can signal the task is still working by dispatching a TaskKeepAliveEvent, without depending on the tasking services:

use BadPixxel\Tasking\Events\TaskKeepAliveEvent;

// Request at least 60 more seconds (defaults to watchdog_delay)
$event = $dispatcher->dispatch(new TaskKeepAliveEvent(60));
if (!$event->isAccepted()) {
    // Task token is about to expire: stop working & let the task be replayed
}

Each signal resets the PHP time limit and marks the task & its worker as alive in database (throttled to one write per refresh_delay). Lifetime is capped by the task token lifetime. Outside a running task, dispatching this event is a no-op.

Note: this feature adds a LastAliveAtTimeStamp column to the tasks table, update your database schema.

Symfony Commands

The bundle comes with management commands to pilot workers from command line.

tasking:check       Tasking Service : Check Supervisor Process is Running on Current Machines
tasking:start       Tasking Service : Start All Supervisors & Workers Process on All Machines
tasking:status      Tasking Service : Check Status of Tasking Services
tasking:stop        Tasking Service : Stop All Supervisors & Workers Process on All Machines
tasking:supervisor  Run a Supervisor Worker Process 
tasking:worker      Run a Tasking Worker Process 

Note: Tasking processes & supervisor are activated & checked each time a new task is added to queue

Configuration reference

Bundle configuration are stored under badpixxel_tasking:

badpixxel_tasking:
    entity_manager: default     // Name of Doctrine Entity Manager to use for Tasks & Token Storage
    environement: prod          // Symfony Environnement to use for workers
    refresh_delay: 3            // Delay for workers status refresh
    watchdog_delay: 30          // Watchdog delay for tasks execution
    multiserver: false          // Enable multiserver mode
    multiserver_path: ''        // Url for remote servers checks 
    server:     
        force_crontab: false    // Use crontab to ensure supervisor is running (Useless if you uses 3+ workers)
        php_version: php        // Bash comamnd for php
    supervisor:
        max_age: 3600           // Time to live of supervisor process, if reached, process will die
        refresh_delay: 500      // Delay between two worker refresh  
        max_workers: 3          // Number of worker to use
        max_memory: 100         // Max. Memory, if reached, process will die
    workers:
        max_tasks: 100          // Max. number of jobs to execute, if reached, process will die
        max_age: 120            // Time to live of a worker process, if reached, process will die
        max_memory: 200         // Max. Memory, if reached, process will die
    tasks:
        max_age: 180            // Time to live of a finished task in database
        try_count: 5            // Number of failed attemps for a task
        try_delay: 120          // Delay before retry of a failed task
    static:                     // Key => Class values for Static Jobs
        myStaticJob: AppBundle\Jobs\MyStaticJob          

Docker Dev Environnement

A Docker Compose file is available to run a development server. You can start it typing the following at the command prompt:

docker-compose up -d

Testing & Code Quality

This bundle uses Phpunit for functional testing.

docker-compose exec app php vendor/bin/phpunit 

This bundle uses Grumphp for all code quality checks (PHPMD, PhpCsFixer, PhpStan, and more...).

docker-compose exec app php vendor/bin/grumphp run 

License

This package is available under the MIT license.