在芹菜任务之后保存/删除Django模型

时间:2016-02-21 04:30:12

标签: python django asynchronous celery django-celery

我所有的Django模型都取决于第三方API的结果。为了保证HTTP调用成功完成,我创建了一组celery任务来保存/删除任何模型来链接它们。一般来说,这些看起来像:

@shared_task
def create(model_data_dict, ModelClass):
    new_model = ModelClass(**model_data_dict)
    new_model.save()

结合HTTP调用,celery任务链类似于

from celery import chain

from model_tasks import create

def create_a_model(model_data_dict):
    chain(
        call_http_api.s(model_data_dict) |
        # Use the result from the HTTP API to create the model
        create.s(AModelClass)
    )        

现在我正在徘徊,如果有更多的Django友好的方法吗?((更开箱即用的东西)。我已经检查了Django on-commit transaction,但这些似乎是针对一个用例,其中任务的结果并不重要。

0 个答案:

没有答案
相关问题