aurimasniekis/scheduler-bundle
Composer 安装命令:
composer require aurimasniekis/scheduler-bundle
包简介
A simple Symfony Job Scheduling Bundle
README 文档
README
A simple scheduler bundle for Symfony which provides a way to execute code at specific cron expressions without modifying cron tab every time.
Install
Via Composer
$ composer require aurimasniekis/scheduler-bundle
Add line to bundle.php:
<?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], // ... AurimasNiekis\SchedulerBundle\AurimasNiekisSchedulerBundle::class => ['all' => true], ];
Add the scheduler to cron tab to run every minute:
* * * * * /path/to/symfony/install/bin/console scheduler:run 1>> /dev/null 2>&1
Usage
Scheduler Bundle uses Symfony Container autoconfigure feature which automatically registers all services
which implement ScheduledJobInterface or NamedScheduledJobInterface interface into Scheduler.
To create a scheduled job you have two options either simple Scheduled Job or Named Scheduled Job. First one uses class name as job name, second provides method to define a job name.
<?php use AurimasNiekis\SchedulerBundle\ScheduledJobInterface; class NamelessJob implements ScheduledJobInterface { public function __invoke(): void { // Execute some logic } public function getSchedulerExpresion(): string { return '*/5 * * * *'; // Run every 5 minutes } }
<?php use AurimasNiekis\SchedulerBundle\NamedScheduledJobInterface; class NamedJob implements NamedScheduledJobInterface { public function __invoke(): void { // Execute some logic } public function getName(): string { return 'named_job'; } public function getSchedulerExpresion(): string { return '*/5 * * * *'; // Run every 5 minutes } }
Console Commands
scheduler:list
List all registered scheduled jobs, and their next scheduled run times
$ bin/console scheduler:list +------------------------------+-------------+---------- Scheduled Jobs -------------------------------------------------------+ | Name | Expression | Next Scheduled Run Times | +------------------------------+-------------+---------------------------------------------------------------------------------+ | named_job | */5 * * * * | 2020-03-22T04:55:00+00:00, 2020-03-22T05:00:00+00:00, 2020-03-22T05:05:00+00:00 | | App\ScheduledJob\NamelessJob | */5 * * * * | 2020-03-22T04:55:00+00:00, 2020-03-22T05:00:00+00:00, 2020-03-22T05:05:00+00:00 | +------------------------------+-------------+---------------------------------------------------------------------------------+
scheduler:execute
Executes a scheduled job manually
$ bin/console scheduler:execute named_job
Executing Scheduled Job: "named_job"
scheduler:run
Command to run all scheduled jobs at this moment. (Used for cron job definition)
* * * * * /path/to/symfony/install/bin/console scheduler:run 1>> /dev/null 2>&1
Testing
Run test cases
$ composer test
Run test cases with coverage (HTML format)
$ composer test-coverage
Run PHP style checker
$ composer cs-check
Run PHP style fixer
$ composer cs-fix
Contributing
Please see CONTRIBUTING and CONDUCT for details.
License
Please see License File for more information.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-22