php - 作业尝试次数过多或运行时间过长
问题描述
我对 Laravel 5.7 中的作业调度有疑问。我需要在工作中提取客户的数据,但是每次我在产品服务器上运行它时,我都会得到
[2020-01-02 13:02:02] production.INFO: Job started
[2020-01-02 13:02:02] production.INFO: ===================
[2020-01-02 13:02:02] production.INFO: Contest: name
[2020-01-02 13:02:02] production.INFO: ===================
[2020-01-02 13:12:08] production.INFO: Job started
[2020-01-02 13:12:08] production.INFO: ===================
[2020-01-02 13:12:08] production.INFO: Contest: name
[2020-01-02 13:12:08] production.INFO: ===================
[2020-01-02 13:22:15] production.INFO: Job started
[2020-01-02 13:22:15] production.INFO: ===================
[2020-01-02 13:22:15] production.INFO: Contest: name
[2020-01-02 13:22:15] production.INFO: ===================
[2020-01-02 13:32:21] production.INFO: Job started
[2020-01-02 13:32:21] production.INFO: ===================
[2020-01-02 13:32:21] production.INFO: Contest: name
[2020-01-02 13:32:21] production.INFO: ===================
[2020-01-02 13:42:28] production.INFO: Job started
[2020-01-02 13:42:28] production.INFO: ===================
[2020-01-02 13:42:28] production.INFO: Contest: name
[2020-01-02 13:42:28] production.INFO: ===================
[2020-01-02 13:44:33] production.ERROR: App\Jobs\SendContestMailToFans has been attempted too many times or run too long. The job may have previously timed out. {"exception":"[object] (Illuminate\\Queue\\MaxAttemptsExceededException(code: 0): App\\Jobs\\SendContestMailToFans has been attempted too many times or run too long. The job may have previously timed out. at /home/forge/loycals.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:401)
[stacktrace]
这是一个工作主体。正如我从日志中看到的那样,工作在拉动收件人时停止。
private function sendContestEmails()
{
Log::info('Job started');
$contest = $this->contest->load([
'prizes',
'primary_sponsor',
'secondary_sponsors',
]);
Log::info('===================');
Log::info('Contest: ' . $contest->title);
Log::info('===================');
$recipients = $contest->primary_sponsor->first()->subscribers()->whereDate('email_sent_at', '<=', Carbon::now()->subWeek()->format('Y-m-d H:i:s'))->orWhereNull('email_sent_at')->get(); // list of subscribers (which is a unique list of fans for that sponsor)
$count = 1;
foreach($recipients as $recipient) {
$count++;
}
Log::info('===================');
Log::info('Recipients: ' . $count);
Log::info('===================');
$sponsor = $contest->primary_sponsor->first();
$subject = 'New Contest at ' . $sponsor->title; // venue title
Log::info('===================');
Log::info('Sponsor: ' . $sponsor->title);
Log::info('===================');
Log::info('Job finished');
}
这是 Forge 上的工人设置: https ://imgur.com/eX6A78V
我还在 config/queue.php 中将“retry_after”设置为 600。我尝试使用超时 0 和默认的“retry_after”运行作业,但遇到了同样的错误。我尝试在登台服务器上使用相同的配置和数据库中的虚拟数据执行此操作,并且该作业已在几秒钟内完成。
解决方案
更改 config/queue.php 中的“retry_after”选项。您应该将“retry_after”值设置为您的作业应该合理地完成处理的最大秒数。
'retry_after' => 1080
推荐阅读
- c# - 有没有办法删除被算作一个字符的空格?
- css - 如何在背景顶部创建曲线?
- javascript - TypeError:无法读取未定义的属性“评级”
- javascript - 如何获取
- reactjs - Browserslist:caniuse-lite 已过时。请运行下一个命令`yarn upgrade`
- reverse-engineering - Windows 10 1909 在 Bochs 中运行非常缓慢
- asp.net - asp .net core 日期时间显示格式
- javascript - 如何在滚动时突出显示/更改颜色为 div
- c++ - (如何)对于初始化指针的数组上的后递增索引,我能否摆脱 C6386 警告?
- google-cloud-storage - 将大文件从 Google Cloud Storage 读取到 Rstudio