basecom / cronjob-bundle
此包已被弃用且不再维护。未建议替代包。
用于编写高效且可线程化的cron作业的包。
2.6.2
2017-11-13 07:00 UTC
Requires
- basecom/wrapper-bundle: >=2.3,<3.0
- mtdowling/cron-expression: ^1.2
- symfony/symfony: >=2.3,<3.0
This package is auto-updated.
Last update: 2024-07-28 00:24:47 UTC
README
许可证信息: LGPL
此包是为了创建强大且高效的cron作业,同时可以使用多线程(需要php PCNTL模块)。
示例
<?php namespace basecom\ExampleBundle\Command; use basecom\CronjobBundle\Command\CronjobCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ExampleCommand extends CronjobCommand { protected function configure() { parent::configure(); $this->setName('basecom:example'); ->setDescription('Shows the easy usage of this nice CronjobBundle'); } protected function executeCronjob(InputInterface $input, OutputInterface $output, $loopcount, $preloopResult = null) { $output->writeln("Hello World!"); } }
在此基本配置中,cron作业将运行约50秒,并且在每次调用executeCronjob()之间将暂停一秒。
如果您触发此命令,您将看到约50次“Hello World!”输出。
crontab处理
您可以使用此包来处理cron作业。然后您可以使用bsc:cronjob:produce
来让工作进程通过配置处理您的命令。
basecom_cronjob:
cronjobs:
- {schedule: '* 5-23 * * *', script: 'app/console app:my:command --no-debug > /dev/null 2>&1'}
并将脚本添加到crontab中,例如运行5分钟:app/console bsc:cronjob:produce --runtime=255 --no-debug > /dev/null 2>&1
或将其添加到工作进程配置中。