【发布时间】:2019-12-18 23:23:02
【问题描述】:
我正在尝试使用 AsyncResult 在不同的辅助函数中访问 celery 任务的 taskid 但无法访问它
https://celery.readthedocs.io/en/latest/reference/celery.result.html#celery.result.AsyncResult
我在此链接上没有得到任何结果,并尝试使用其他一些链接,例如 https://docs.celeryproject.org/en/latest/userguide/tasks.html
def anotherFunction(data):
try:
fvlfn
except Exception as identifier:
logging.exception(identifier)
@app.task(bind=True)
def send(self):
try:
TASKID = self.request.id
anotherFunction('no if s')
except Exception as identifier:
self.update_state(state='ALMOST DONE')
logging.exception(self.request.id)
我想在 anotherFunction 中访问 taskid 而不通过它
【问题讨论】:
-
app.current_task.request.id你会在程序的任何地方得到当前的taskid -
我认为你想为 Sentry 启用 Celery 集成,而不是做你所做的。 docs.sentry.io/platforms/python/celery那个会在活动页面底部的“附加数据”中附上任务ID。
-
它附加任务 id,如果任务是从客户端调用的。如果我们只是调用任务而不等待响应,哨兵添加数据将不包含 taskId,我们必须手动添加任务 id,在过滤函数中
标签: python celery scheduled-tasks