7.获取任务结果# 在views.py中,通过AsyncResult.get()获取结果 Copy defget_result(request): task_id = request.GET.get('task_id') ar = result.AsyncResult(task_id)ifar.ready():returnJsonResponse({"status": ar.state,"result": ar.get()})else:returnJsonResponse({"status": ar.state,"result"...
async_result=AsyncResult(id="c6ddd5b7-a662-4f0e-93d4-ab69ec2aea5d", app=cel)ifasync_result.successful(): result= async_result.get() print(result) # result.forget() # 将结果删除 elif async_result.failed(): print('执行失败') elif async_result.status=='PENDING': print('任务等待中...
from app import taskres = task.delay("古明地觉", 17)print(type(res))"""<class 'celery.result.AsyncResult'>"""# 直接打印,显示任务的 idprint(res)"""4bd48a6d-1f0e-45d6-a225-6884067253c3"""# 获取状态, 显然此刻没有执行完# 因此结果是PENDING, 表示等待状态print(res.status)"""PENDING...
AsyncResult 主要用来储存任务执行信息与执行结果,有点类似 tornado 中的 Future 对象,都有储存异步结果与任务执行状态的功能,对于写 js 的朋友,它有点类似 Promise 对象,当然在 Celery 4.0 中已经支持了 promise 协议,只需要配合 gevent 一起使用就可以像写 js promise 一样写回调: import gevent.monkey monkey.pa...
celery -A celery_tasks worker --loglevel=INFO -P gevent>>> async_result2=AsyncResult(id="4395edbc-fa90-4fe1-be5a-6ddb74c6e317", app=app) >>> async_result2.status 'SUCCESS' >>> 如此就会发现可以正常执行任务了。celery命令下的输出也会有改变,会提示收到一个任务,任务干了些什么,最后状态...
fromappimporttaskres=task.delay("古明地觉",17)print(type(res))"""<class 'celery.result.AsyncResult'>"""# 直接打印,显示任务的 idprint(res)"""4bd48a6d-1f0e-45d6-a225-6884067253c3"""# 获取状态, 显然此刻没有执行完# 因此结果是PENDING, 表示等待状态print(res.status)"""PENDING"""# 获...
在django怎么使用celery.AsyncResult 使用celery.AsyncResult可以获取Celery任务的状态和结果。 1. 引入AsyncResult from celery.result import AsyncResult 2. 获取任务结果 result = AsyncResult(task_id) if result.successful(): result_value = result.get()...
小弟在学习celery的过程中遇到了一个问题:在使用apply_async调用任务后 ,无法通过celery.result.Asyncresult(id='任务id')获取对应的任务状态,返回值等信息,会报错:'DisabledBackend' object has no attribute '_get_task_meta_for' worker能够正常启动并执行任务,启动页面如下: --- celery@177.17.17.242.static.host...
要检索任务的结果,可以使用AsyncResult对象。AsyncResult对象是任务的异步结果的代理,可以通过它来获取任务的状态和结果。例如: 代码语言:txt 复制 from tasks import add result = add.delay(4, 5) print(result.status) # 检查任务的状态 if result.ready(): # 检查任务是否已完成 print(result.result) # 获取...
from celery_task.celery import app from celery.result import AsyncResult id = '21325a40-9d32-44b5-a701-9a31cc3c74b5' if __name__ == '__main__': async = AsyncResult(id=id, app=app) if async.successful(): result = async.get() print(result) elif async.failed(): print('任务失败...