【问题标题】:re-run jobs in laravel scheduler在 laravel 调度程序中重新运行作业
【发布时间】:2018-02-24 16:56:47
【问题描述】:

如果失败,我想在 laravel 调度程序中重新运行作业,假设如下:
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;
     }
   });
 }

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

有什么建议吗?

【问题讨论】:

    标签: php laravel laravel-5 laravel-scheduler


    【解决方案1】:

    您在匿名函数中以错误的方式设置 $schedule,请像这样使用“使用”语句:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 1970-01-01
      • 2018-07-16
      • 2011-08-07
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      相关资源
      最近更新 更多