无法在同一任务的辅助函数中访问 Celery 任务的任务 ID?
unable to acces taskid of Celery task in helper fucntion of the same task?
我正在尝试使用 AsyncResult 在不同的辅助函数中访问 celery 任务的 taskid,但无法访问它
https://celery.readthedocs.io/en/latest/reference/celery.result.html#celery.result.AsyncResult
我在这个 link 上获得了 None 并尝试了其他一些 link,例如 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 而不传递它
您始终可以使用 Celery 应用程序对象来获取有关当前任务的信息:myapp.current_task.request.id
(其中 myapp 是 Celery class 的一个实例)
然而,仅仅因为你可以并不意味着你应该这样做。我们中的许多人更喜欢显式地将函数所需的数据传递给 运行,而不是使用一些全局对象。
我正在尝试使用 AsyncResult 在不同的辅助函数中访问 celery 任务的 taskid,但无法访问它
https://celery.readthedocs.io/en/latest/reference/celery.result.html#celery.result.AsyncResult
我在这个 link 上获得了 None 并尝试了其他一些 link,例如 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 而不传递它
您始终可以使用 Celery 应用程序对象来获取有关当前任务的信息:myapp.current_task.request.id
(其中 myapp 是 Celery class 的一个实例)
然而,仅仅因为你可以并不意味着你应该这样做。我们中的许多人更喜欢显式地将函数所需的数据传递给 运行,而不是使用一些全局对象。