您可以创建两个芹菜应用程序并将celery.py重命名为celery_app.py以避免自动导入。
from celery import Celery app1 = Celery('hello', broker='amqp://guest@localhost//') @app1.task def hello1(): return 'hello world from local'
和
from celery import Celery app2 = Celery('hello', broker='amqp://guest@remote//') @app2.task def hello2(): return 'hello world from remote'
对于共享任务:
from celery import shared_task @shared_task def add(x, y): return x + y
当您运行芹菜工作者节点时:
celery --app=PACKAGE.celery_app:app worker