如果发生故障,我想在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}()
有什么建议吗?
答案 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;
}
});
}