Scheduler Bundle
Push scheduled tasks to messenger.
Release Plan
| Release | Supported OpenDXP Versions | Supported Symfony Versions | Release Date | Maintained | Branch |
|---|---|---|---|---|---|
| 1.x | ^1.0 | ^7.3 | 2025 | Feature Branch | 1.x |
Installation
"require" : {
"open-dxp/scheduler-scheduler": "^1.0",
}
Add Bundle to bundles.php:
return [
OpenDxp\Bundle\SchedulerBundle\OpenDxpSchedulerBundle::class => ['all' => true],
];
- Execute:
$ bin/console opendxp:bundle:install OpenDxpSchedulerBundle
Register Task
App\Scheduler\MyScheduledTask:
tags:
- { name: scheduler.task, type: my_scheduled_task }
<?php
namespace App\Scheduler;
use OpenDxp\Bundle\SchedulerBundle\Scheduler\TaskInterface;
final class TestSchedulerTask implements TaskInterface
{
/**
* This method is only required, if you're loading your tasks via resource,
* where it is not possible to determinate tag properties!
*
* Example:
*
* App\Scheduler\:
* resource: '../../src/Scheduler'
* tags: [ 'scheduler.task' ]
*/
public static function getDefaultTypeName(): string
{
return 'my_scheduled_task';
}
public function execute(): void
{
// do something
// [...]
// and throw a simple exception, if something went wrong
// this exception will be transported to the application logger ("scheduler" component)
throw new \Exception('task failed because of reasons');
}
public function getCronExpression(): string
{
// every 5 minutes
return '*/5 * * * *';
}
public function getLockKey(): ?string
{
// if you're returning a string value,
// scheduler will store a lock fragment in tmp store
// to prevent simultaneous running jobs
return null;
}
}
List tasks
If you want to execute tasks manually, type following command to list all available commands:
$ bin/console scheduler -h
Run task worker
$ bin/console messenger:consume scheduler
Dispatch (execute) task
If you want to execute tasks manually, type:
$ bin/console scheduler my_scheduled_task
License
DACHCOM.DIGITAL AG, Löwenhofstrasse 15, 9424 Rheineck, Schweiz
dachcom.com, [email protected]
Copyright © 2024 DACHCOM.DIGITAL. All rights reserved.
For licensing details please visit LICENSE.md