-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tasks.py
44 lines (36 loc) · 1.22 KB
/
test_tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import random
from tasks import add, mul
x = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
y = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
print "x={0}, {1}".format(x, y)
result = mul.delay(x, y)
print result.id # message id
print "mul.delay(x, y)={0}".format(result.get())
result = mul.apply_async((x, y), countdown=5) # Same as add.delay(2, 2)
print result.id # message id
print "mul.delay(x, y)={0}".format(result.get())
result = add.apply_async((2, 2))
print result.get()
print 'result.successful(): {0}'.format(result.successful())
print result.state # SUCCESS
# Enhance above, create/send mesage to queue name 'lopri'
# add.apply_async((2, 2), queue='lopri', countdown=5)
# get propagated error if any
try:
result = add.delay(x)
result.get() # propagate=True by default
except Exception as e:
print '========='
print e
# disable propagated error if any
try:
result = add.delay(x)
result.get(propagate=False)
except Exception as e:
print '---------'
print e
print 'result.failed(): {0}'.format(result.failed())
print result.state # FAILURE
# Canvas/subtask
# group/map/chain/starmap/chord/chunks check out this:
# http://docs.celeryproject.org/en/latest/getting-started/next-steps.html#next-steps