tourze / symfony-cron-job-bundle
Symfony 定时任务
0.0.3
2025-03-27 07:54 UTC
Requires
- php: ^8.1
- composer/ca-bundle: ^1.5.6
- dragonmantank/cron-expression: ^3.4
- psr/container: ^1.1|^2.0
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/lock: ^6.4
- symfony/process: ^6.4
- symfony/var-dumper: ^6.4
- tiben/crontab-manager: ^1.4
- tourze/bundle-dependency: 0.0.*
- tourze/symfony-async-bundle: 0.0.*
This package is auto-updated.
Last update: 2025-04-20 08:15:02 UTC
README
A Symfony bundle for managing and running cron jobs with flexible scheduling, registration, and async execution support.
Features
- Register cron jobs via PHP attribute or provider interface
- Auto-generate crontab entries and manage them programmatically
- Asynchronous execution of scheduled commands
- Support for custom cron expressions
- Built-in commands for running and scheduling jobs
- Integrates with Symfony Messenger and Lock
Installation
Requirements
- PHP >= 8.1
- Symfony >= 6.4
- Extensions:
posix
,pcntl
Install via Composer
composer require tourze/symfony-cron-job-bundle
Quick Start
1. Register a Cron Job
Use the AsCronTask
attribute on your Symfony command:
use Tourze\Symfony\CronJob\Attribute\AsCronTask; #[AsCronTask('0 * * * *')] // runs every hour class MyHourlyCommand extends Command { ... }
Or implement the CronCommandProvider
interface to provide jobs dynamically.
2. Add Cron Entry
php bin/console cron-job:add-cron-tab
This registers the main cron entry in your system crontab.
3. Start the Scheduler
php bin/console cron:start
This starts a process to check and run due cron jobs every minute.
Documentation
- Cron job registration via attribute or provider
- Custom cron expressions
- Async execution with Messenger
- Advanced configuration: see source code and comments
Contributing
- Open issues or pull requests on GitHub
- Follow PSR coding standards
- Write and run tests before submitting PRs
License
MIT License. See LICENSE for details.
Changelog
See Git history for latest changes and releases.