Pass parameters to Celery on_error task

时光总嘲笑我的痴心妄想 提交于 2021-01-27 22:01:15

问题


I'm using celery with rabbitMQ as a broker to manage asynchronous tasks.

I'm chording some tasks together and when each of them has finished, I'm running a concatenation task that will join each result. These collection of tasks is identified by a report_id set by me.

chord([task1.s(report_id=report_id), task2.s(report_id=report_id)...]) \
 (concat_task.s(report_id=report_id).set(queue='default') \
 .on_error(on_chord_error.s().set(queue='default')))

And this is my custom on_error task:

@celery_app.task
def on_chord_error(request, exc, traceback):
    logger.error('Chord {0!r} raised error: {1!r}'.format(request.id, exc), exc_info=(type(exc), exc.args, traceback))
    # BaseHandler.remove_placeholder(???report_id???)  # cleaning action

My problem is on the on_error: Every time the chord fails (for any reason) I need to have the report_id (not to be confused with the request.id) passed to it in order to perform a cleaning action. However the documentation I found is vague on this. It seems I cannot pass the request_id as parameter of the task signature as I am doing for the singles and concatenation tasks.

Any help would be appreciated

来源:https://stackoverflow.com/questions/59575336/pass-parameters-to-celery-on-error-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!