Artisan Schedule运行不运行所有命令

问题描述 投票:0回答:4

我正在尝试让Laravel Scheduler运行几个命令,但是当我运行php artisan schedule:run时,它只会运行kernal.php文件中的一个命令。

我的Kernel.php文件如下:

protected $commands = [
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('a:import')->everyMinute();
    $schedule->command('b:import')->everyFiveMinutes();
}

/**
 * Register the Closure based commands for the application.
 *
 * @return void
 */
protected function commands()
{
    require base_path('routes/console.php');
}

我的console.php文件包含以下代码:

Artisan::command('a:import', function(a\ImportController $runner) {
    $runner->init();
});

Artisan::command('b:import', function(b\ImportController 
$runner) {
    $runner->beginImport();
});

当我运行php artisan schedule:run我得到以下结果:

D:\development\v2> php artisan schedule:run

 ´╗┐Running scheduled command: "C:\Program Files\PHP\v7.0\php.exe" "artisan" a:import > "NUL" 2>&1

任何帮助,以确定我错过了什么或我需要做的任何其他事情将不胜感激。

php laravel artisan laravel-scheduler
4个回答
0
投票

输出可能有点误导,但实际上是有效的。你将a:import设置为每分钟运行一次,b:importto每5分钟运行一次,这样当你运行时:

php工匠时间表:运行

你会看到a:import命令比b:import经常运行5次


0
投票

你有没有设置一个cron,当然它不会运行...


0
投票

您是否在crontab中添加了schedule命令?


0
投票

您必须在$ commands数组中注册自定义命令:

protected $commands = [
    Commands\A::class,
    Commands\B::class
];
© www.soinside.com 2019 - 2024. All rights reserved.