Laravel Task Schedule与数据库中的Cron列

我有一个“ reportSchedule”模型,其中包含报告名称和一个cron_request列,例如*/15 * * * *

我希望能够调整数据库中的cron并影响请求报告的时间。例如,下面的内容直接在console / Kernel.php中进行:

ReportSchedule::all()->each(function(ReportSchedule $reportSchedule) use($schedule){
    if(isset($reportSchedule->cron_request)){
        $schedule->call(function() use ($reportSchedule) {
            ReportRequestNow::dispatch($reportSchedule);
        })->cron($reportSchedule->cron_request);
    }
});

但是,直接从内核内部调用模型会导致其他问题。例如,数据库迁移现在不起作用,并且在缓存路由或运行route:list时会引发错误。一般来说,它似乎不喜欢它!

所以我的想法是要么创建一个播种者工作,要么将其放入自己的计划中,但是没有任何作用。

//不起作用-每隔一分钟便被调用,但从没到达ReportRequestNow。

$schedule->call(function() use($schedule){
    ReportSchedule::all()->each(function(ReportSchedule $reportSchedule) use($schedule){
        if(isset($reportSchedule->cron_request)){
            $schedule->call(function() use ($reportSchedule) {
                ReportRequestNow::dispatch($reportSchedule);
            })->cron($reportSchedule->cron_request);
        }
    });
})->everyMinute();

//也不起作用

$schedule->job(new ReportScheduleSeeder(),'high')->everyMinute();

任何人都可以提出一个为什么这样不起作用或如何使其起作用的建议吗?

zjfshy 回答:Laravel Task Schedule与数据库中的Cron列

  

但是,直接在内核中调用模型   导致其他问题。例如,数据库迁移现在不起作用   缓存路由或运行route:list时会引发错误。   一般来说,它似乎不喜欢它!

似乎有一些语法错误(也许某些类未在使用中列出?)

您检查过laravel和PHP日志吗?很有可能会有一些解释。

本文链接:https://www.f2er.com/3166160.html

大家都在问