forked from ziadsawalha/example_celery_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
44 lines (35 loc) · 1014 Bytes
/
test.py
File metadata and controls
44 lines (35 loc) · 1014 Bytes
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
'''
Test use case
$python test.py
Success: 3
Failure:
- state: RETRY
- ready: False
- get: >> got exception: EngineTaskError Failed
Zero: Done Normally
Five: Done Rushed!
$
'''
from subprocess import Popen
from engine import celery, tasks
pid = Popen(['celery', 'worker', '--app=engine', '-q'])
async_success = tasks.success.delay(1, 2)
async_failure = tasks.failure.delay()
async_zero = tasks.run_long.delay(0)
async_five = tasks.run_long.delay(5)
result = async_success.get()
print "********************************************"
print "Success:", result
print "Failure:"
print "- state:", async_failure.state
print "- ready:", async_failure.ready()
try:
print "- get:", async_failure.get(timeout=3)
except StandardError as exc:
print ">> got exception:", exc
print "********************************************"
print "Zero:", async_zero.get()
print "Five:", async_five.get()
pid.terminate()
print "********************************************"
print "Done!"