10
我想使用django-celery
添加任意任務的延遲。目前,我已經創建類似下面的一個類(只是一個例子,實際的班有比這更):django-celery:動態創建並註冊一項任務
from celery.task import task
class Delayer(object):
def delay(self, func, minutes):
return task(func, name="%s.delayed"%self.__class__.__name__)\
.apply_async(countdown=minutes*60)
我跑celeryd如下:
python manage.py celeryd -E -B -lDEBUG
當我嘗試從Django的外殼內運行我的延時方法[例如Delayer().delay(lambda: 1, 1)
],我得到這樣的錯誤在我celeryd輸出:
[2013-01-02 15:26:39,324: ERROR/MainProcess] Received unregistered task of type "Delayer.delayed".
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.
The full contents of the message body was:
{'retries': 0, 'task': "Delayer.delayed", 'eta': '2013-01-02T21:27:39.320913', 'args': [], 'expires': None, 'callbacks': None, 'errbacks': None, 'kwargs': {}, 'id': '99d49fa7-bd4b-40b0-80dc-57309a6f19b1', 'utc': True} (229b)
Traceback (most recent call last):
File "/home/simon/websites/envs/delayer/local/lib/python2.7/site-packages/celery/worker/consumer.py", line 432, in on_task_received
strategies[name](message, body, message.ack_log_error)
KeyError: "Delayer.delayed"
我的問題是,是不是可以註冊這樣的動態科瑞編輯任務?如果沒有,我可以使用其他什麼方法來使用芹菜來達到相同的效果?