dbh / symfony-schedule-bundle
clone from m-adamski/symfony-schedule-bundle
Installs: 2 409
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 2
Type:symfony-bundle
Requires
- php: ^7.2|^8.0
- dragonmantank/cron-expression: 3.1.*
- symfony/console: 5.4.*
- symfony/framework-bundle: 5.4.*
- symfony/lock: 5.4.*
README
Schedule Bundle for Symfony
Bundle for simplifying operations with CRON jobs.
Installation
This Bundle can be installed by Composer:
$ composer require Dbh/symfony-schedule-bundle
How to use it?
Bundle provide functionality to manage CRON jobs by configuration from specified file.
We need to create class implementing Dbh\Symfony\ScheduleBundle\Model\ManagerInterface
interface.
namespace App\Model;
use Dbh\Symfony\ScheduleBundle\Model\ManagerInterface;
use Dbh\Symfony\ScheduleBundle\Model\Schedule;
class ScheduleManager implements ManagerInterface {
public function schedule(Schedule $schedule) {
// TODO: ..
}
}
Then we need to complete the configuration - create file config/packages/schedule.yaml
and set path to ScheduleManager:
schedule:
manager: App\Model\ScheduleManager
Command schedule configuration
In function schedule
we can configure CRON jobs with required expressions.
For example we want run app:test-command
daily at 12:00:
public function schedule(Schedule $schedule) {
$schedule->command("app:test-command")->dailyAt("12:00");
}
Schedule class provide many date-time manipulators. This functionality is inspired by Laravel Tasks Scheduling.
Schedule Frequency Options
There are many schedules that you can assign to your task.
CRON
Now it's enough to insert only one entry into crontab on server:
* * * * * php /path-to-project/bin/console schedule:run >> schedule.log 2>&1
License
MIT