2

我在我的应用程序中配置了 django-celery。这是我的任务:

from celery.decorators import task
import simplejson as json
import requests

@task
def call_api(sid):
    try:
        results = requests.put(
            'http://localhost:8000/api/v1/sids/'+str(sid)+"/",
            data={'active': '1'}
        )
        json_response = json.loads(results.text)
    except Exception, e:
        print e
    logger.info('Finished call_api')

当我在我的视图中添加:

call_api.apply_async(
                (instance.service.id,),
                eta=instance.date
            )

芹菜向我展示:

Got task from broker: my_app.tasks.call_api[755d50fd-0f0f-4861-9a18-7f4e4563290a]
Task my_app.tasks.call_api[755d50fd-0f0f-4861-9a18-7f4e4563290a] succeeded in 0.00513911247253s: None

所以应该很好,但什么也没发生......没有调用例如:

 http://localhost:8000/api/v1/sids/1/

我究竟做错了什么?

4

1 回答 1

0

您是否将 celery 作为一个单独的进程运行?例如在 Ubuntu 中使用命令 sudo python manage.py celeryd 运行

直到您将 celery(或 django celery)作为单独的进程运行,作业将存储在数据库中(或队列或您配置的持久性机制 - 通常在 settings.py 中)。

于 2013-06-20T14:36:15.897 回答