def redis_example(request): res = add.delay(2,3) return HttpResponse('%d' % res.get(timeout=1))
def index(request): p1 = request.GET.get('p1') p2 = request.GET.get('p2') add.delay(p1, p2) return HttpResponse("hi, you're in djcelery_pro index")
# !/usr/bin/env python # -*- coding: utf-8 -*- from demoapp.tasks import add if __name__ == '__main__': re = add.delay(1, 2) print(re)
# -*- coding: utf-8 -*- """ @Time : 2018-08-24 13:57 @Author : DukeMoon """ import datetime import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj.settings") import django django.setup() from demoapp.tasks import add if __name__ == '__main__': print("实时任务") print(datetime.datetime.now().isoformat()) res = add.delay(2, 3) print(datetime.datetime.now().isoformat()) print("result:", res.get()) print(datetime.datetime.now().isoformat()) print("延时任务") res = add.apply_async((2, 3), countdown=3) print(datetime.datetime.now().isoformat()) print("result:", res.get()) print(datetime.datetime.now().isoformat())
def see_view(request): add.delay(10,10) return HttpResponse("<h1>MyCelery</h1>")
def home(request): res = add.delay(2, 50) return HttpResponse(res.get())