如何在 AWS Elastic Beanstalk 上运行 celery Worker?

2023-12-06

版本:

  • 姜戈 1.9.8
  • 芹菜 3.1.23
  • django-celery 3.1.17
  • Python 2.7

我正在尝试在 AWS Elastic Beanstalk 上运行我的 celery 工作线程。我使用 Amazon SQS 作为 celery 代理。

这是我的设置.py

INSTALLED_APPS += ('djcelery',)
import djcelery
djcelery.setup_loader()
BROKER_URL = "sqs://%s:%s@" % (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY.replace('/', '%2F'))

当我在终端上输入下面的行时,它会在我的本地启动工作程序。我还创建了一些任务并且它们执行正确。我如何在 AWS EB 上执行此操作?

python manage.py celery worker --loglevel=INFO

我发现了thisStackOverflow 上的问题。 它说我应该将 celery 配置添加到 .ebextensions 文件夹中,该文件夹在部署后执行脚本。但这不起作用。我将不胜感激任何帮助。安装supervisor后,我没有对它做任何事情。也许这就是我所缺少的。 这是脚本。

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash

      # Get django environment variables
      celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'`
      celeryenv=${celeryenv%?}

      # Create celery configuration script
      celeryconf="[program:celeryd]
      command=/opt/python/run/venv/bin/celery worker --loglevel=INFO

      directory=/opt/python/current/app
      user=nobody
      numprocs=1
      stdout_logfile=/var/log/celery-worker.log
      stderr_logfile=/var/log/celery-worker.log
      autostart=true
      autorestart=true
      startsecs=10

      ; Need to wait for currently executing tasks to finish at shutdown.
      ; Increase this if you have very long running tasks.
      stopwaitsecs = 600

      ; When resorting to send SIGKILL to the program to terminate it
      ; send SIGKILL to its whole process group instead,
      ; taking care of its children as well.
      killasgroup=true

      ; if rabbitmq is supervised, set its priority higher
      ; so it starts first
      ; priority=998

      environment=$celeryenv"

      # Create the celery supervisord conf script
      echo "$celeryconf" | tee /opt/python/etc/celery.conf

      # Add configuration script to supervisord conf (if not there already)
      if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf
          then
          echo "[include]" | tee -a /opt/python/etc/supervisord.conf
          echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf
      fi

      # Reread the supervisord config
      supervisorctl -c /opt/python/etc/supervisord.conf reread

      # Update supervisord in cache without restarting all services
      supervisorctl -c /opt/python/etc/supervisord.conf update

      # Start/Restart celeryd through supervisord
      supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd

来自 EB 的日志:看起来可以工作,但仍然没有执行我的任务。

-------------------------------------
/opt/python/log/supervisord.log
-------------------------------------
2016-08-02 10:45:27,713 CRIT Supervisor running as root (no user in config file)
2016-08-02 10:45:27,733 INFO RPC interface 'supervisor' initialized
2016-08-02 10:45:27,733 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2016-08-02 10:45:27,733 INFO supervisord started with pid 2726
2016-08-02 10:45:28,735 INFO spawned: 'httpd' with pid 2812
2016-08-02 10:45:29,737 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2016-08-02 10:47:14,684 INFO stopped: httpd (exit status 0)
2016-08-02 10:47:15,689 INFO spawned: 'httpd' with pid 4092
2016-08-02 10:47:16,727 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2016-08-02 10:47:23,701 INFO spawned: 'celeryd' with pid 4208
2016-08-02 10:47:23,854 INFO stopped: celeryd (terminated by SIGTERM)
2016-08-02 10:47:24,858 INFO spawned: 'celeryd' with pid 4214
2016-08-02 10:47:35,067 INFO success: celeryd entered RUNNING state, process has stayed up for > than 10 seconds (startsecs)
2016-08-02 10:52:36,240 INFO stopped: httpd (exit status 0)
2016-08-02 10:52:37,245 INFO spawned: 'httpd' with pid 4460
2016-08-02 10:52:38,278 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2016-08-02 10:52:45,677 INFO stopped: celeryd (exit status 0)
2016-08-02 10:52:46,682 INFO spawned: 'celeryd' with pid 4514
2016-08-02 10:52:46,860 INFO stopped: celeryd (terminated by SIGTERM)
2016-08-02 10:52:47,865 INFO spawned: 'celeryd' with pid 4521
2016-08-02 10:52:58,054 INFO success: celeryd entered RUNNING state, process has stayed up for > than 10 seconds (startsecs)
2016-08-02 10:55:03,135 INFO stopped: httpd (exit status 0)
2016-08-02 10:55:04,139 INFO spawned: 'httpd' with pid 4745
2016-08-02 10:55:05,173 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2016-08-02 10:55:13,143 INFO stopped: celeryd (exit status 0)
2016-08-02 10:55:14,147 INFO spawned: 'celeryd' with pid 4857
2016-08-02 10:55:14,316 INFO stopped: celeryd (terminated by SIGTERM)
2016-08-02 10:55:15,321 INFO spawned: 'celeryd' with pid 4863
2016-08-02 10:55:25,518 INFO success: celeryd entered RUNNING state, process has stayed up for > than 10 seconds (startsecs)

解决这个问题后我忘了添加答案。 这就是我修复它的方法。 我在 .ebextensions 文件夹中创建了一个新文件“99-celery.config”。 在此文件中,我添加了此代码并且它运行良好。 (不要忘记在第 16 行更改您的项目名称,我的是 molocate_eb)

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash

      # Get django environment variables
      celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'`
      celeryenv=${celeryenv%?}

      # Create celery configuraiton script
      celeryconf="[program:celeryd]
      ; Set full path to celery program if using virtualenv
      command=/opt/python/current/app/molocate_eb/manage.py celery worker --loglevel=INFO

      directory=/opt/python/current/app
      user=nobody
      numprocs=1
      stdout_logfile=/var/log/celery-worker.log
      stderr_logfile=/var/log/celery-worker.log
      autostart=true
      autorestart=true
      startsecs=10

      ; Need to wait for currently executing tasks to finish at shutdown.
      ; Increase this if you have very long running tasks.
      stopwaitsecs = 600

      ; When resorting to send SIGKILL to the program to terminate it
      ; send SIGKILL to its whole process group instead,
      ; taking care of its children as well.
      killasgroup=true

      ; if rabbitmq is supervised, set its priority higher
      ; so it starts first
      priority=998

      environment=$celeryenv"

      # Create the celery supervisord conf script
      echo "$celeryconf" | tee /opt/python/etc/celery.conf

      # Add configuration script to supervisord conf (if not there already)
      if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf
          then
          echo "[include]" | tee -a /opt/python/etc/supervisord.conf
          echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf
      fi

      # Reread the supervisord config
      supervisorctl -c /opt/python/etc/supervisord.conf reread

      # Update supervisord in cache without restarting all services
      supervisorctl -c /opt/python/etc/supervisord.conf update

      # Start/Restart celeryd through supervisord
      supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd

编辑:如果 AWS 上出现主管错误,请确保;

  • 您使用的是 Python 2 而不是 Python 3,因为主管不适用于 Python 3。
  • 不要忘记将主管添加到您的requirements.txt 中。
  • 如果它仍然给出错误(发生在我身上一次),只需“重建环境”,它可能会起作用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 AWS Elastic Beanstalk 上运行 celery Worker? 的相关文章

随机推荐

  • 如何处理“变量时间”(DATE、双精度、8 字节)?

    我似乎找不到任何有关 变体时间 的信息 DATE 双精度 8 字节变量 被处理 我有一个不同的时间 A 哪个值是 41716 892329 如果我转换 A 使用 变体时间到系统时间 or COle日期时间 我明白 2014 03 18 21
  • 移动向量会使迭代器失效吗?

    如果我有一个向量迭代器a 然后我移动构造或移动分配向量b from a 该迭代器是否仍然指向同一个元素 现在在向量中 b 这就是我在代码中的意思 include
  • 如何使用存储过程在sql server 2008中拆分字符串并将数据插入表

    我想以这种格式分割一个字符串 引用 date 10 10 2000 age 13 date 01 01 2001 age 12 date 02 02 2005 age 8 实际上这个字符串只是一个示例 我的原始字符串非常大 我不明白的是 如
  • 在 ASP.NET MVC 2 中 - 如何将路由值获取到导航控制器中,以便突出显示当前链接?

    我正在尝试将当前路线放入导航控制器中 以便在填充导航菜单数据时可以运行比较 我的链接对象是这样的 public class StreamNavLinks public string Text get set public RouteValu
  • Struts2;为 StrutsSpringTestCase JUnit 测试保持会话打开

    我的项目架构是带有 Spring 集成和 JPA Hibernate 的 Struts2 StrutsSpringTestCase 基类用于 JUnit 集成测试 正常情况下 web xml 中的以下配置使单个会话从每个请求的开始到结束保持
  • 退出应用程序会让人不悦吗?

    继续尝试学习 Android 我只是阅读以下 问题 用户是否可以选择终止应用程序 除非我们添加一个菜单选项来杀死它 如果不存在这样的选项 用户如何终止应用程序 答案 Romain Guy 用户不这样做 系统会自动处理此问题 这就是 Acti
  • OpenCV 中的人脸识别

    我试图使用 OpenCV 2 2 来自 Willow Garage 构建一个基本的人脸识别系统 PCA Eigenfaces 我从之前关于人脸识别的许多帖子中了解到 没有标准的开源库可以为您提供所有人脸识别功能 相反 我想知道是否有人使用过
  • 如何在heroku中设置超过30秒的响应超时

    伙计们 如果响应返回时间超过 30 秒 Heroku 将终止请求 那么有什么方法可以让我等待响应返回呢 好吧 用户正在上传他的文件 我需要对服务器中的文件执行一些操作 更新完成后 我将向用户提供下载链接 但服务器处理文件的时间大多超过30秒
  • Rails 5、Heroku 与 Let's Encrypt SSL - 配置设置时遇到问题

    我正在尝试弄清楚如何使用 heroku 上的 Rails 应用程序进行加密 我已经尝试了几个 gem 它们似乎是为帮助完成此过程而设计的 letsencrypt plugin 但删除了这些 gem 推荐的所有安装步骤 因为我无法正常工作 现
  • 矢量填充和调整大小

    我正在研究地图生成器 我使用二维向量来保存数据 Header class MapGenerator public protected std vector lt std vector
  • 防止以编程方式缓存脚本

    我想问一下有没有办法阻止Firefox缓存脚本 js文件 我有一个项目 ASP Net Web App 在 Firefox 上存在缓存问题 当我第一次运行应用程序 脚本正在 Firefox 上缓存 并修改脚本并重新运行应用程序时 Firef
  • 如何获取运行时x:Name值

    I got
  • 如何选择从Excel运行的.NET框架版本?

    除了将 excel exe config 文件添加到 Office Binary 文件夹之外 如何指定 Excel 在运行 NET dll 时使用 NET Framework 版本 2 0 我们的应用程序在 Excel 中运行 并使用 VB
  • mypy可以根据当前对象的类型选择方法返回类型吗?

    在下面的代码中 调用clone 在 A 的实例上调用该方法将返回 A 类型的实例 在 B 的实例上调用该方法将返回 B 类型的实例 依此类推 目的是创建一个与当前实例相同但具有不同的内部生成主键的新实例 因此可以从那里对其进行编辑并安全地另
  • ng-model 作为二维数组中的变量

    p span span p
  • 检查 int 是否为素数 Java

    对 修复我的代码 帖子感到抱歉 编辑 与语法更多相关for循环比质数 现在也解决了 我的任务是从控制台获取一个 int 并打印出 在单独的行上 从 1 到 n 含 的所有素数 我的方法从 n 开始 检查是否为素数 然后将 n 递减 1 并循
  • 事件和自引用组件 vue.js

    我有允许 1 级线程的评论系统 意味着第一级评论看起来像 内容 线 其中线程可能有更多评论 我认为这对于自引用组件和带有插槽的列表很有用 但过了一会儿我不知道如何连接这个东西 SingleComment 组件如下
  • 时间列应使用什么数据类型

    在我的 Spark 应用程序中 我必须拆分时间和数据并将它们存储在单独的列中 如下所示 val df5 df4 withColumn read date date format df4 col date yyyy MM dd withCol
  • 在 R 中安装旧包时出错

    我正在尝试安装 0 6 2 版本的 tm 库 我已经从以下位置下载了 tar gz 文件archive并在 RStudio 中选择 工具 gt 存档 gt 打包存档文件 来安装它 但是 我收到以下错误 有人可以帮我解决这个问题吗 安装sou
  • 如何在 AWS Elastic Beanstalk 上运行 celery Worker?

    版本 姜戈 1 9 8 芹菜 3 1 23 django celery 3 1 17 Python 2 7 我正在尝试在 AWS Elastic Beanstalk 上运行我的 celery 工作线程 我使用 Amazon SQS 作为 c