最终与该项目布局一起工作
proj/celery_proj/__init__.py
/celery.py
/tasks.py
/test.py
哪里
芹菜
from __future__ import absolute_import
from celery import Celery
app = Celery('celery_proj',
broker='amqp://',
backend='amqp://',
include=['celery_proj.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
)
if __name__ == '__main__':
app.start()
task.py
from __future__ import absolute_import
from celery_proj.celery import app
@app.task
def add(x, y):
return x + y
@app.task
def mul(x, y):
return x * y
@app.task
def xsum(numbers):
return sum(numbers)
test.py
__author__ = 'mehdi'
path = '/home/mehdi/PycharmProjects'
import sys
sys.path.append(path)
from celery_proj.tasks import add
r = add.delay(4,4)
print(r.status)
print(r.result)
并通过以下方式启动工作人员:
cd proj
celery -A celery_proj worker -l info
然后运行test.py:
python test.py