Revision 3e99e2d1 flowspec/tasks.py
b/flowspec/tasks.py | ||
---|---|---|
1 | 1 |
from utils import proxy as PR |
2 | 2 |
from celery.task import task |
3 |
from celery.task.sets import subtask |
|
4 |
import logging |
|
5 |
from celery.task.http import * |
|
6 |
from flowspy.utils import beanstalkc |
|
7 |
from django.conf import settings |
|
8 |
|
|
9 |
FORMAT = '%(asctime)s %(levelname)s: %(message)s' |
|
10 |
logging.basicConfig(format=FORMAT) |
|
11 |
logger = logging.getLogger(__name__) |
|
12 |
logger.setLevel(logging.DEBUG) |
|
3 | 13 |
|
4 | 14 |
@task |
5 |
def add(route): |
|
15 |
def add(route, callback=None):
|
|
6 | 16 |
applier = PR.Applier(route_object=route) |
7 | 17 |
commit, response = applier.apply() |
8 | 18 |
if commit: |
... | ... | |
14 | 24 |
route.is_online = is_online |
15 | 25 |
route.is_active = is_active |
16 | 26 |
route.response = response |
27 |
subtask(announce).delay("Route add: %s - Result: %s" %(route.name, response)) |
|
28 |
route.save() |
|
29 |
|
|
30 |
@task |
|
31 |
def edit(route, callback=None): |
|
32 |
applier = PR.Applier(route_object=route) |
|
33 |
commit, response = applier.apply(operation="replace") |
|
34 |
if commit: |
|
35 |
is_online = True |
|
36 |
else: |
|
37 |
is_online = False |
|
38 |
route.is_active = True |
|
39 |
route.is_online = is_online |
|
40 |
route.response = response |
|
17 | 41 |
route.save() |
42 |
subtask(announce).delay("Route edit: %s - Result: %s" %(route.name, response)) |
|
43 |
|
|
44 |
|
|
18 | 45 |
|
19 | 46 |
@task |
20 |
def multi(x,y): |
|
21 |
return x*y |
|
22 |
# |
|
23 |
#@task |
|
47 |
def delete(route, callback=None): |
|
48 |
applier = PR.Applier(route_object=route) |
|
49 |
commit, response = applier.apply(operation="delete") |
|
50 |
if commit: |
|
51 |
is_online = False |
|
52 |
is_active = False |
|
53 |
else: |
|
54 |
is_online = route.is_online |
|
55 |
is_active = route.is_active |
|
56 |
route.is_online = is_online |
|
57 |
route.is_active = is_active |
|
58 |
route.response = response |
|
59 |
route.save() |
|
60 |
subtask(announce).delay("Route delete: %s - Result %s" %(route.name, response)) |
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
@task |
|
65 |
def announce(messg): |
|
66 |
messg = str(messg) |
|
67 |
b = beanstalkc.Connection() |
|
68 |
b.use(settings.POLLS_TUBE) |
|
69 |
b.put(messg) |
|
70 |
b.close() |
|
71 |
|
|
72 |
|
|
24 | 73 |
#def delete(route): |
25 | 74 |
# |
26 | 75 |
# applier = PR.Applier(route_object=route) |
Also available in: Unified diff