12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\console\command;
- use app\console\service\DailyBonus as DailyBonusService;
- use app\console\service\MonthlyBonusClear;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- use Workerman\Crontab\Crontab;
- use Workerman\Worker;
- class Cron extends Command
- {
- protected function configure()
- {
- log_record('aaa','error');
- $this->setName('croner')
- ->addArgument('status', Argument::REQUIRED, 'start/stop/reload/status/connections')
- ->addOption('d', null, Option::VALUE_NONE, 'daemon(守护进程)方式启动')
- ->setDescription('Cron Gold Command');
- }
- protected function execute(Input $input, Output $output)
- {
- $worker = new Worker();
- $worker->count = 4;
- // 设置时区,避免运行结果与预期不一致
- date_default_timezone_set('PRC');
- log_record('ccc','error');
- $worker->onWorkerStart = function ($worker) {
- log_record(date('ID--->'.$worker->id),'error');
- /* new Crontab('* * * * * *', function(){
- log_record(date('Y-m-d H:i:s'),'error');
- });*/
- // 每分钟的第1秒执行.00::05:01 todo
- //new Crontab('1 5 0 * * *', function(){
- /* new Crontab('1 * * * * *', function(){
- echo date('Y-m-d H:i:s')."\n";
- $service = new DailyBonusService;
- $service->calBonusMoney(10001);
- });*/
- // 每天的7点50执行,注意这里省略了秒位.20日 01:01:00秒 todo
- //new Crontab('1 1 20 * *', function(){
- /* new Crontab('1 * * * * *', function(){
- echo "monthly job!"."\n";
- $service = new MonthlyBonusClear();
- $service->clearBonusMoney(10001);
- });*/
- };
- Worker::runAll();
- }
- }
|