Esempio n. 1
0
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'})
Esempio n. 2
0
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"))
Esempio n. 3
0
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)
Esempio n. 4
0
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"})
Esempio n. 5
0
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"})
Esempio n. 6
0
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'})
Esempio n. 7
0
def index(request):
    print('start index')
    CourseTask.delay()
    print('end index')
    return HttpResponse('hello celery')
Esempio n. 8
0
def do(request):
    print('start do request')
    CourseTask.delay()
    print('end do request')

    return JsonResponse({'result': 'ok'})
Esempio n. 9
0
def do(request):
    print('into do...')
    CourseTask().delay()
    print('goto do...')
    return JsonResponse({'result': "ok"})