回调之前的Laravel 5.1不起作用

时间:2015-12-04 12:14:47

标签: php laravel-5.1 scheduler

在回调不工作之前,在Laravel 5.1中的任务调度程序中:

protected function schedule(Schedule $schedule)
{
    $schedule->command('inspire')->hourly();
    $schedule->command('view:clear')->daily();
    $schedule->call(function(){
        ToolsController::fixCategory();
        })
        ->everyMinute()
        ->before(function () {
            // Task is about to start...
            Log::info('Start fixing Category');
        })
        ->after(function () {
            // Task is complete...
            Log::info('End fixing Category');
        });

}

在日志文件中:

[2015-12-04 12:02:22] local.INFO: End fixing Category  
[2015-12-04 12:06:08] local.INFO: End fixing Category  

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

感谢@Svetlio

命令类:

class FixCategory extends Command
{
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'FixCategory';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Fix Category';

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    ToolsController::fixCategory();
}
}

内核类:

class Kernel extends ConsoleKernel
{
/**
 * The Artisan commands provided by your application.
 *
 * @var array
 */
protected $commands = [
    \App\Console\Commands\Inspire::class,
    \App\Console\Commands\FixCategory::class,
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('inspire')->hourly();
    $schedule->command('view:clear')->daily();
    $schedule->command('FixCategory')
        ->everyMinute()
        ->before(function () {
            // Task is about to start...
            Log::info('Start fixing Category');
        })
        ->after(function () {
            // Task is complete...
            Log::info('End fixCategory');
        });
}
}

日志文件:

[2015-12-04 12:44:49] local.INFO: Start fixing Category  
[2015-12-04 12:44:50] local.INFO: End fixing Category