在laravel调度程序中重新运行作业

时间:2017-09-15 13:19:38

标签: php laravel laravel-5 laravel-scheduler

如果发生故障,我想在laravel Scheduler中重新运行作业,假设如下:
Kernal.php

protected function schedule(Schedule $schedule)
{
    $this->generateData($schedule);

}

protected function generateData($schedule){

   $schedule->command('My Command')
   ->monthly()
   ->after(function ($schedule){
     $command = DB::table('commands')
     ->where("name","My Command")
     ->orderBy('id', 'desc')
     ->first();
     if(!$command->succeeded){
       echo "task not finished";
       $this->generateData($schedule);
     }
     else{
       echo "task finished";
       return;
     }
   });
 }

此命令有时会失败,在函数I之后检查命令是否失败,然后我尝试再次重新执行它,但这没有工作,我得到以下错误:
[ ErrorException]   缺少App \ Console \ Kernel :: App \ Console {closure}()

的参数1

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

你在匿名函数中设置了$ schedule错误的方法,使用这样的'use'语句:

protected function generateData($schedule){

  $schedule->command('My Command')
  ->monthly()
  ->after(function() use ($schedule){
    $command = DB::table('commands')
    ->where("name","My Command")
    ->orderBy('id', 'desc')
    ->first();
    if(!$command->succeeded){
      echo "task not finished";
      $this->generateData($schedule);
    }
    else{
      echo "task finished";
      return;
    }
  });
}