2016-11-25 82 views
1

我有一些任務應該返回結果,一些任務不。 我想強制任何不應返回結果而不在結果後端寫入任何內容(例如None)的任務。我如何在Celery中實現這一點?芹菜任務沒有結果寫入結果後端

例如,它是我的任務:

@app.task 
def taskWithResult(): 
    # ...code... 
    return res 

@app.task 
def taskWithNoResult(): 
    # ...code without return... 

而且我也有一些其他的任務,也不會返回任何結果的特殊隊列,我可以標記該隊列與任務,其中千萬不能」 t寫入結果後端?

回答

3

從芹菜文件,你可以設置忽略結果標誌爲真。 http://docs.celeryproject.org/en/latest/reference/celery.app.task.html?highlight=default_retry_delay#celery.app.task.Task.ignore_result

例如:

@app.task(ignore_result=True) 
def taskWithNoResult(): 
    # ...code without return.. 
+0

是標記任務隊列中的任何方式? –

+0

您可以使用apply_async選擇任務隊列。 [鏈接](http://docs.celeryproject.org/en/latest/userguide/calling.html?highlight=apply_async#routing-options) – Jinje