示例#1
0
from proj.tasks import add, mul, xsum, hello

print(group(add.s(i, i) for i in range(10))().get())
g = group(add.s(i) for i in range(200))
print(g(10).get())

# (4 + 4) * 9
print(chain(add.s(4, 4) | mul.s(9))().get())

# (? + 4) * 8
c = chain(add.s(4) | mul.s(8))
print(c(4).get())

print(chord((add.s(i, i) for i in range(10)), xsum.s())().get())

a = add.apply_async(args=(1, 1), kwargs={}, countdown=10, expires=120)
r = add.s(1, 1).apply_async(countdown=10)
print(r.state)


def on_raw_message(body):
    print(body)


r = hello.apply_async(args=(3, 5))
print(r.get(on_message=on_raw_message, propagate=False))

r = signature('tasks.add', args=(2, 2), countdown=10)
print(r)
r = add.signature((2, 2), {}, countdown=10)
print(r.args, r.kwargs, r.options)
示例#2
0
from  proj.tasks import add, mul
from proj.celeryconfig import A_QUEUE, M_QUEUE
import time


if __name__ == '__main__':
    add_result = add.apply_async((2, 2), queue=A_QUEUE)
    # sleep 1 seconds to ensure the task has been finished
    time.sleep(1)
    # now the task should be finished and ready method will return True
    print(f'add task finished? {add_result.ready()}')
    print(f'add task result: {add_result.result}')

    mul_result = mul.delay(3, 3)
    # at this time, our task is not finished, so it will return False
    print(f'mul task finished? {mul_result.ready()}')
    print(f'mul task result: {mul_result.result}')
    # sleep 10 seconds to ensure the task has been finished
    time.sleep(10)
    # now the task should be finished and ready method will return True
    print(f'mul task finished? {mul_result.ready()}')
    print(f'mul task result: {mul_result.result}')
    
示例#3
0
# coding:utf-8
import time
from proj.tasks import add, mul

res_add = add.apply_async((2, 3))
res_mul = mul.apply_async((4, 5))

print(res_add)
print(res_mul)
print(res_mul.ready())
print(res_mul.ready())

# time.sleep(3)

# print(res_add.get())
# print(res_mul.get())
示例#4
0
from proj.tasks import add
from datetime import datetime, timedelta
#res = add.delay(4, 4)
res = add.apply_async(args=[4], countdown=1)
print res.get()
next_time = datetime.utcnow() + timedelta(seconds=3)
print next_time
print datetime.now()
res = add.apply_async(args=[3, 5], eta=next_time)
print res.get()
示例#5
0
from proj.tasks import  add

# result=add.delay(4,4)
result=add.apply_async((4,4))
print(result.ready())
print(result.get(timeout=1))

s1=add.s(4,4)
result=s1.delay()
print(result.get())
示例#6
0
from proj.tasks import add, div, sub
from proj.celery import app
from celery import group
'''for show state app'''
res = app.AsyncResult(
    '16d5d64a-28ed-4b6a-97e0-5787b2f335fe')  #this id of output  run tasks
print(res.successful())
print(res.failed())
print(res.state)
print(res.id)

func = add.signature(
    (2, 18))  #(2, 18) default for task add this add to the end task
#add.s(18) this s not accept to parameter
res = func.delay()  # this add to the end
res.forget()

rs = add.delay(5, 2)
print(rs.get())

rs = div.delay(63, 3)
print(rs.get())

result = sub.apply_async((5, 6), queue='celery', countdown=3)
print(result.get())
'''
add.apply_async(args=[5,6], countdown=10) #10 secound delay fro run and asyncrinize change to syncrinize
print(rs.get(timeout=2)) #if more than of 2 secound not response then leave it
print(rs.get(propagate=False)) #if eror was you leave and continue run code

'''
示例#7
0
文件: diaoyong.py 项目: yooinn/Python
from proj.tasks import add

import time
t1 = time.time()

r2 = add.apply_async((3, 4), queue='for_task_ADD')
r3 = add.apply_async((5, 12), queue='for_task_ADD')
r4 = add.apply_async((12, 22), queue='for_task_ADD')
r5 = add.apply_async((32, 42), queue='for_task_ADD')
r_list = [r2, r3, r4, r5]
for r in r_list:
    print(r.id)
    print(r.get())
    # while not r.ready():
    #     pass
    # print(r.result)

t2 = time.time()

print('共耗时:%s' % str(t2 - t1))