luiswagener/symfony-cron-bundle
最新稳定版本:0.1
Composer 安装命令:
composer require luiswagener/symfony-cron-bundle
包简介
Scheduled background jobs for Symfony applications, with persistent tracking of execution history.
README 文档
README
Contao-style cron framework for Symfony applications. Register cron jobs with a single attribute, run them from a single minutely server cron, and persist last-run timestamps in the database.
Installation
composer require luiswagener/symfony-cron-bundle
Register the bundle in config/bundles.php:
Luiswagener\SymfonyCronBundle\SymfonyCronBundle::class => ['all' => true],
Create the database table:
php bin/console doctrine:migrations:diff php bin/console doctrine:migrations:migrate
Doctrine must have auto_mapping: true (Symfony default) so the bundle entity is discovered automatically.
Server cron
Configure one minutely cron job on your server:
* * * * * /usr/bin/php /path/to/your-app/bin/console cron:run
Defining cron jobs
Place a class anywhere under src/ and annotate it with #[AsCronJob]. No service registration or tagging is required — standard Symfony autowiring picks it up automatically.
use Luiswagener\SymfonyCronBundle\Attribute\AsCronJob; #[AsCronJob('hourly')] final class CleanupExpiredTokensCron { public function __construct(private TokenRepository $tokens) {} public function __invoke(): void { $this->tokens->deleteExpired(); } }
Supported intervals
- Presets:
minutely,hourly,daily,weekly,monthly,yearly - Cron expressions:
0 * * * *,*/5 * * * * - Human-readable:
1 minute,every 5 minutes,1 hour
Command usage
php bin/console cron:run php bin/console cron:run "App\\Cron\\CleanupExpiredTokensCron" php bin/console cron:run --force php bin/console cron:run "App\\Cron\\CleanupExpiredTokensCron" --force
Skipping execution
Throw CronExecutionSkippedException to skip a job without updating last_run:
use Luiswagener\SymfonyCronBundle\Exception\CronExecutionSkippedException; public function __invoke(string $scope): void { if ($scope !== Cron::SCOPE_CLI) { throw new CronExecutionSkippedException(); } }
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-10