byfareska / cron-bundle
Symfony cron
v1.0.1
2023-06-09 13:55 UTC
Requires
- php: >=7.4
- symfony/framework-bundle: ^3.4|^4.4|^5.0|^6.0
Requires (Dev)
- symfony/symfony: >=4.0
This package is not auto-updated.
Last update: 2024-09-27 19:55:32 UTC
README
快速设置
- 添加到cron任务
* * * * * php bin/console cron:run
- 创建一个实现
\Byfareska\Cron\Task\ScheduledTask
的类,例如
final class DeleteFileEveryHourTask implements ScheduledTask { public function cronInvoke(DateTimeInterface $now, bool $forceRun, OutputInterface $output): bool { if($forceRun || $now->format('i') === '0'){ $this(); return true; } return false; } public function __invoke(): void { unlink('/var/example'); } }
有用的命令
强制运行某些任务
php bin/console cron:run --task=App\\Task\\DeleteFileEveryHourTask,App\\Task\\AnotherTask
列出所有已注册的任务
php bin/console debug:container --tag=cron.task