如何在芹菜中创建子任务



http://celery.readthedocs.org/en/v2.2.6/userguide/tasksets.html

项目/

celery.py

from __future__ import absolute_import
from kombu import Exchange, Queue
from celery import Celery
app = Celery('proj',
             broker='redis://myredis.com',
             backend='redis://myredis.com',
             include=['proj.tasks'])
a_exchange = Exchange('a_ex', type='topic')
# Optional configuration, see the application user guide.
app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600,
    CELERY_DISABLE_RATE_LIMITS=True,
    CELERY_ROUTES = {"app.tasks.timeme": "a"}
)
if __name__ == '__main__':
    app.start()

tasks.py

from __future__ import absolute_import
from proj.celery import app
import time
@app.task
def timeme(ts):
    print 'hi'
    lat = time.time() - float(ts)
    return (lat, time.time())

do_tasks.py

import proj.tasks
import time
import sys
stime = time.time()
while time.time() < stime + 15:
    res = proj.tasks.timeme.apply_async(args=[time.time()], link=proj.tasks.timeme())

当我运行do_task.py时,它给我抛出了一个错误:

TypeError: timeme() takes exactly 1 argument(0 given)

我知道link有一些问题,因为如果我不指定link它就可以正常工作

我的猜测是,timeme必须是一个子任务。
我不确定如何将时间指定为子任务。

谁能帮忙?

我只需要把.之后s()

res = proj.tasks.timeme.apply_async(args=[time.time()], link=proj.tasks.timeme.s())

最新更新