def do(request): # 执行异步任务 print('start do request') # CourseTask.delay() CourseTask.apply_async(args=('hello', ), queue='work_queue') # 指定queue print('end do request') return JsonResponse({'result': 'ok'})
def do(request): print("start do request") # 此处不需要再实例化 通过元类创建 <class 'celery.app.task.TaskType'> # CourseTask.delay() CourseTask.apply_async(args=("hello", ), queue="beat_tasks") print("end do request") return JsonResponse(dict(result="OK"))
def do(request): print("Start do request...") # CourseTask.delay() # delay执行队列,没有填写指定队列的话,会默认执行配置文件设置默认的队列 CourseTask.apply_async(args=('hello', ), queue='work_queue') # 传入参数,并指定work_queue队列 print("End do request...") result = {'result': 'waiting...'} return JsonResponse(result)
def do(request): # 执行异步任务 print('start do request') # CourseTask.delay() # 另一种调用方法 CourseTask.apply_async(args=('hello',), queue='work_queue') print('end do request') return JsonResponse({"status_code": 200, "result": "success"})
def course_task(request): print("start course_task") # both delay and apply_async are async # if some more args need to be passed, it is better to use apply_async # CourseTask.delay(1, 2) CourseTask.apply_async(args=("hello", "world"), queue="ordinary_tasks") print("end course_task") return JsonResponse({"res": "ok"})
def do(request): # 执行异步任务 print('start do request') for i in range(100): result = CourseTask.delay() print(result) # CourseTask.apply_async(args=('hello',), queue='work_queue') print('end do request') return JsonResponse({'result': 'ok'})
def index(request): print('start index') CourseTask.delay() print('end index') return HttpResponse('hello celery')
def do(request): print('start do request') CourseTask.delay() print('end do request') return JsonResponse({'result': 'ok'})
def do(request): print('into do...') CourseTask().delay() print('goto do...') return JsonResponse({'result': "ok"})