简体   繁体   中英

Laravel 5.1 before callback is not working

In task scheduler in Laravel 5.1 before callback not working:

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');
        });

}

In log file:

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

Any idea ?

Thanks for @Svetlio

Command Class:

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();
}
}

Kernel Class:

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');
        });
}
}

Log file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM