【发布时间】:2013-12-09 03:53:27
【问题描述】:
我有一台带有 2 个项目的服务器,每个项目都有不同的用途,但都需要使用 celery 运行调度程序任务。
我想在同一台服务器上创建单独的 celery daemon,我尝试创建不同的配置文件并使用 2 个不同的进程运行它。
app1 任务.py
from celery import task
@task()
def task_1(data):
print("run task 1.")
app1配置文件:
# Name of nodes to start, here we have a single node
CELERYD_NODES="w1"
# Where to chdir at start.
CELERYD_CHDIR="/usr/app1/task_scheduler/"
# Extra arguments to celeryd
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# Name of the celery config module.
CELERY_CONFIG_MODULE="celeryconfig"
# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/tmp/%n.log"
CELERYD_PID_FILE="/tmp/%n.pid"
app1,celeryconfig.py
BROKER_URL = 'amqp://guest:guest@localhost:5672//'
CELERY_IMPORTS=("tasks")
CELERY_RESULT_BACKEND = "amqp"
CELERY_ENABLE_UTC = False
app2 任务.py
from celery import task
@task()
def task_2(data):
print("run task 2.")
app2 配置与 app1 配置相同,除了 CELERYD_CHDIR 和 CELERYD_NODES。 app2 celeryconfig.py 与 app1 相同
我的问题是当我在 app1 上添加新任务时
from tasks import *
if __name__ == "__main__":
...
task_1.apply_async(args=data, eta=t)
task_1 在 app1 节点上按预期运行,但此任务都添加到 app2 节点。因为节点 2 没有定义此函数,所以在节点 2 日志上引发了 not_found 函数。它仍然可以工作,但我如何设置让 task_1 只发送到 app1 celery 节点。我的意思是节点 2 不会收到 task_1 任务。
【问题讨论】:
-
我遇到了类似的问题。我通过更改其中一名工作人员及其相应的 redis 守护程序的端口来解决它。看到这个:serverfault.com/questions/527311/…
标签: python scheduled-tasks celery daemon