【问题标题】:Celery and Celerybeat are running, but don't run tasksCelery 和 Celerybeat 正在运行,但不运行任务
【发布时间】:2019-06-25 00:31:03
【问题描述】:

我已经在本地服务器上检查了我的代码,我确信我的代码一切正常。所以服务器配置似乎有问题。我有一个 linux 服务器 (Ubuntu 16.04) 并安装了 nginx、redis ……我还为 celery 和 celerybeat 创建了配置文件,如下所示:

  • /etc/init.d/celeryd
  • /etc/default/celeryd
  • /etc/init.d/celerybeat
  • /etc/default/celerybeat

我检查了它们的状态,它们都在运行,但是当我检查 beat.log 时,它什么也没做,只显示“正在启动...”

芹菜文件:

# Names of nodes to start
CELERYD_NODES="worker"

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/home/amirali/AwesomeApp/awesome_env/bin/celery"


# App instance to use
CELERY_APP="AwesomeApp"


# Where to chdir at start. Where your manage.py is...
CELERYD_CHDIR="/home/amirali/AwesomeApp"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 -Ofair --concurrency=8"

# Set logging level to DEBUG
CELERYD_LOG_LEVEL="INFO"

# %n will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Workers should run as an unprivileged user.
#   You need to create this user manually (or you can choose
#   a user/group combination that already exists (e.g., nobody).
CELERYD_USER="celery"
CELERYD_GROUP="celery"

# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1

celerybeat 文件:

  File: /etc/default/celerybeat                                                                                                                                                              
  CELERYBEAT_LOG_LEVEL="info"
  # Absolute or relative path to the 'celery' command:
  CELERY_BIN="/home/amirali/AwesomeApp/awesome_env/bin/celery"

  CELERYBEAT_USER="celery"
  CELERYBEAT_GROUP="celery"
  # App instance to use
  # comment out this line if you don't use an app
  CELERY_APP="AwesomeApp"
  # or fully qualified:
  #CELERY_APP="proj.tasks:app"

  # Where to chdir at start.
  CELERYBEAT_CHDIR="/home/amirali/AwesomeApp"

  # Extra arguments to celerybeat
  CELERYBEAT_OPTS="--schedule=/var/run/celery/celerybeat-schedule"
  export DJANGO_SETTINGS_MODULE="AwesomeApp.settings"

【问题讨论】:

  • 您在这里期待什么?您是否自己发送了作业,例如使用.delay,或者是否有计划运行的作业?
  • 是的,我创建了我的任务文件,它可以与 'celery -A proj beat -l info' 命令一起使用。当我想将worker作为守护进程运行时,问题就出现了。
  • 那么工人有什么问题呢?当它运行时您希望看到什么?您看到了什么?
  • 我只是在 beat.log 中查看调度程序消息。类似于“调度程序:发送到期任务 [task_name]”。但它只显示“beat: Starting...”
  • 任务很简单,它必须向我的电报频道发送一个字符串。

标签: django nginx redis celery celerybeat


【解决方案1】:

当我们不得不执行 celery 周期性任务时,结果发现celery-beat 无法正常工作,它只是在某个时刻停止了启动任务。

经过一些测试,我们决定不再在这上面浪费时间,而是依赖 linux crontab 实用程序

【讨论】:

    最近更新 更多