我有一个运行Laravel的EB工人环境(单个实例),该环境用于运行计划和调度的作业。
我面临的问题是,每分钟多次调用cron,从而导致计划的工作加倍。这可以在工作人员的访问日志中看到;
-------------------------------------
/var/log/httpd/access_log
-------------------------------------
127.0.0.1 (-) - - [27/Feb/2019:00:07:01 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:01 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:01 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:01 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:01 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:07 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:07 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:08 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:09 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:09 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:09 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:10 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:11 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:07:11 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:15 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:16 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:08:48 +0000] "POST /scheduled.php HTTP/1.1" 302 215 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
127.0.0.1 (-) - - [27/Feb/2019:00:09:00 +0000] "POST /worker/schedule HTTP/1.1" 302 217 "-" "aws-sqsd/2.4"
在CloudWatch日志中导致类似的重复;
20:40:00 INFO: Processing /2019/20190225.csv [] []
20:40:00 INFO: Processing /2019/20190225.csv [] []
20:40:00 INFO: Processing /2019/20190225.csv [] []
20:40:01 INFO: Processing /2019/20190225.csv [] []
20:40:01 INFO: Processing /2019/20190225.csv [] []
20:40:02 INFO: Processing /2019/20190225.csv [] []
20:40:02 INFO: Processing /2019/20190225.csv [] []
20:40:03 INFO: Processing /2019/20190225.csv [] []
20:40:03 INFO: Processing /2019/20190225.csv [] []
20:40:04 INFO: Processing /2019/20190225.csv [] []
20:40:04 INFO: Processing /2019/20190225.csv [] []
20:40:06 INFO: Processing /2019/20190225.csv [] []
20:40:06 INFO: Processing /2019/20190225.csv [] []
20:40:06 INFO: Processing /2019/20190225.csv [] []
20:40:06 INFO: Processing /2019/20190225.csv [] []
20:40:06 INFO: Processing /2019/20190225.csv [] []
20:40:06 INFO: Processing /2019/20190225.csv [] []
我正在使用dusterio/laravel-aws-worker与SQS队列进行交互以处理调度的作业。
工作者在cron.yaml
中具有以下内容;
version: 1
cron:
- name: "schedule"
url: "/worker/schedule"
schedule: "* * * * *"
我工人的控制台内核正在安排这样的每小时工作;
protected function schedule(Schedule $schedule)
{
$schedule->job(new ImportData())
->hourly()
->timezone(config('app.timezone')); // Pacific/Auckland
}
我这里缺少什么吗?
答案 0 :(得分:0)
对于那些偶然发现此问题的人来说,问题在于我的应用程序正在发生HTTPS重定向,并且同一应用程序已部署到Web层和工作层。 302响应将导致SQS重试到最大重试限制,但是每个调用仍在执行作业。
一种解决方案是从此重定向中排除SQS代理;
files:
/etc/httpd/conf.d/http-redirect.conf:
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !ELB-HealthChecker
RewriteCond %{HTTP_USER_AGENT} !aws-sqsd
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
另一种方法是查看防止将此脚本部署到工作人员环境。