bearframework/tasks-addon

Tasks addon for Bear Framework

Maintainers

Package info

github.com/bearframework/tasks-addon

pkg:composer/bearframework/tasks-addon

Statistics

Installs: 2 054

Dependents: 5

Suggesters: 0

Stars: 0

Open Issues: 0

v1.6.0 2025-12-06 22:41 UTC

README

A lightweight task scheduling and execution addon for Bear Framework. It lets you register task handlers, enqueue work items with scheduling and priority options, and process them via a runnable worker.

Snippets

Define task (register handler)

$app->tasks
    ->define('definition-id', function ($value): void {
        // code
    })

Add task

$app->tasks
    ->add('definition-id', 'example-value', [
        'id' => 'task-id', // optional
        'listID' => '', // empty value for the default list
        'startTime' => time() + 120, // start in 2 minutes
        'priority' => 3, // 1 - lowest, 5 - highest
        'ignoreIfExists' => true, // will check the id only
    ]);

Run tasks

$app->tasks
    ->addEventListener('runTask', function (\BearFramework\Tasks\RunTaskEventDetails $eventDetails) use ($app) {
        $app->logs->log('run-task', $eventDetails->definitionID);
    })
    ->run([
        'listID' => '',
        'maxExecutionTime' => 30
    ]);

Contributing

Contributions and bug reports are welcome. Open issues or submit pull requests to the repository.

License

This addon is free to use under the MIT license. See the LICENSE file for details.