umen7使用笔记之定时任务 (十五)Mac下lumen7跑定时任务测试

399 次浏览次阅读
没有评论

app\Console\Commands 目录下新建一个定时任务文件

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class MacCronTestController extends Command
{
    protected $signature = 'testconsole';

    protected $description = 'first console';

    public function __construct()
    {parent::__construct();
    }

    public function handle()
    {Log::info('12334');
    }

}

编辑 app\Console\Kernel.php 文件

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
use App\Console\Commands\MacCronTestController; # 引入

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
        MacCronTestController::class # 定时任务文件名
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        //
        $schedule->command('testconsole')->everyMinute(); # 定时任务 $signature}
}

crontab -e

* * * * * cd /Users/cailianjie/work/lumen7 && php artisan schedule:run >> /dev/null 2>&1
查看 storage\logs 目录新的日志 是否定时任务跑成功
手动执行命令

php artisan testconsole

正文完
 0
评论(没有评论)