ElasticBeanstalk worker cron每分钟运行多次

问题描述 投票:0回答:1

我有一个运行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
}

这里有什么我想念的吗?

laravel amazon-web-services amazon-sqs amazon-elastic-beanstalk
1个回答
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}

另一种方法是防止将此脚本部署到工作线程环境。

© www.soinside.com 2019 - 2024. All rights reserved.