0

我试图让 Laravel 调度程序运行几个命令,但是当我运行php artisan schedule:run它时,它只会运行 kernal.php 文件中的一个命令。

我的 Kernal.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

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

4

4 回答 4

0

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

protected $commands = [
    Commands\A::class,
    Commands\B::class
];
于 2019-04-02T15:51:52.267 回答
0

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

于 2017-11-02T04:31:16.653 回答
0

输出可能有点误导,但实际上是有效的。您设置a:import为每分钟运行一次并且b:import每 5 分钟运行一次,因此当您运行时:

php工匠时间表:运行

您会看到该a:import命令的运行频率是 5 次b:import

于 2017-11-01T17:40:26.843 回答
0

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

于 2017-11-01T18:15:52.107 回答