Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flowspy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
flowspy
Commits
98b30771
Commit
98b30771
authored
Aug 07, 2014
by
Leonidas Poulopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include timeout handling in tasks
parent
f929870f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
42 deletions
+84
-42
flowspec/tasks.py
flowspec/tasks.py
+84
-42
No files found.
flowspec/tasks.py
View file @
98b30771
...
...
@@ -29,6 +29,7 @@ from django.core.mail import send_mail
from
django.template.loader
import
render_to_string
from
django.core.urlresolvers
import
reverse
import
os
from
celery.exceptions
import
TimeLimitExceeded
,
SoftTimeLimitExceeded
...
...
@@ -47,48 +48,95 @@ logger.addHandler(handler)
@
task
(
ignore_result
=
True
)
def
add
(
route
,
callback
=
None
):
applier
=
PR
.
Applier
(
route_object
=
route
)
commit
,
response
=
applier
.
apply
()
if
commit
:
status
=
"ACTIVE"
else
:
status
=
"ERROR"
route
.
status
=
status
route
.
response
=
response
route
.
save
()
announce
(
"[%s] Rule add: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
response
),
route
.
applier
)
try
:
applier
=
PR
.
Applier
(
route_object
=
route
)
commit
,
response
=
applier
.
apply
()
if
commit
:
status
=
"ACTIVE"
else
:
status
=
"ERROR"
route
.
status
=
status
route
.
response
=
response
route
.
save
()
announce
(
"[%s] Rule add: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
response
),
route
.
applier
)
except
TimeLimitExceeded
:
route
.
status
=
"ERROR"
route
.
response
=
"Task timeout"
route
.
save
()
announce
(
"[%s] Rule add: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
except
SoftTimeLimitExceeded
:
route
.
status
=
"ERROR"
route
.
response
=
"Task timeout"
route
.
save
()
announce
(
"[%s] Rule add: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
except
Exception
:
route
.
status
=
"ERROR"
route
.
response
=
"Error"
route
.
save
()
announce
(
"[%s] Rule add: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
@
task
(
ignore_result
=
True
)
def
edit
(
route
,
callback
=
None
):
applier
=
PR
.
Applier
(
route_object
=
route
)
commit
,
response
=
applier
.
apply
(
operation
=
"replace"
)
if
commit
:
status
=
"ACTIVE"
else
:
status
=
"ERROR"
route
.
status
=
status
route
.
response
=
response
route
.
save
()
announce
(
"[%s] Rule edit: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
response
),
route
.
applier
)
try
:
applier
=
PR
.
Applier
(
route_object
=
route
)
commit
,
response
=
applier
.
apply
(
operation
=
"replace"
)
if
commit
:
status
=
"ACTIVE"
else
:
status
=
"ERROR"
route
.
status
=
status
route
.
response
=
response
route
.
save
()
announce
(
"[%s] Rule edit: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
response
),
route
.
applier
)
except
TimeLimitExceeded
:
route
.
status
=
"ERROR"
route
.
response
=
"Task timeout"
route
.
save
()
announce
(
"[%s] Rule edit: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
except
SoftTimeLimitExceeded
:
route
.
status
=
"ERROR"
route
.
response
=
"Task timeout"
route
.
save
()
announce
(
"[%s] Rule edit: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
except
Exception
:
route
.
status
=
"ERROR"
route
.
response
=
"Error"
route
.
save
()
announce
(
"[%s] Rule edit: %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
@
task
(
ignore_result
=
True
)
def
delete
(
route
,
**
kwargs
):
applier
=
PR
.
Applier
(
route_object
=
route
)
commit
,
response
=
applier
.
apply
(
operation
=
"delete"
)
reason_text
=
''
if
commit
:
status
=
"INACTIVE"
if
"reason"
in
kwargs
and
kwargs
[
'reason'
]
==
'EXPIRED'
:
status
=
'EXPIRED'
reason_text
=
" Reason: %s "
%
status
else
:
status
=
"ERROR"
route
.
status
=
status
route
.
response
=
response
route
.
save
()
announce
(
"[%s] Suspending rule : %s%s- Result %s"
%
(
route
.
applier
,
route
.
name
,
reason_text
,
response
),
route
.
applier
)
try
:
applier
=
PR
.
Applier
(
route_object
=
route
)
commit
,
response
=
applier
.
apply
(
operation
=
"delete"
)
reason_text
=
''
if
commit
:
status
=
"INACTIVE"
if
"reason"
in
kwargs
and
kwargs
[
'reason'
]
==
'EXPIRED'
:
status
=
'EXPIRED'
reason_text
=
" Reason: %s "
%
status
else
:
status
=
"ERROR"
route
.
status
=
status
route
.
response
=
response
route
.
save
()
announce
(
"[%s] Suspending rule : %s%s- Result %s"
%
(
route
.
applier
,
route
.
name
,
reason_text
,
response
),
route
.
applier
)
except
TimeLimitExceeded
:
route
.
status
=
"ERROR"
route
.
response
=
"Task timeout"
route
.
save
()
announce
(
"[%s] Suspending rule : %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
except
SoftTimeLimitExceeded
:
route
.
status
=
"ERROR"
route
.
response
=
"Task timeout"
route
.
save
()
announce
(
"[%s] Suspending rule : %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
except
Exception
:
route
.
status
=
"ERROR"
route
.
response
=
"Error"
route
.
save
()
announce
(
"[%s] Suspending rule : %s - Result: %s"
%
(
route
.
applier
,
route
.
name
,
route
.
response
),
route
.
applier
)
# May not work in the first place... proxy is not aware of Route models
@
task
...
...
@@ -122,8 +170,7 @@ def batch_delete(routes, **kwargs):
#@task(ignore_result=True)
def
announce
(
messg
,
user
):
messg
=
str
(
messg
)
# username = user.username
username
=
user
.
get_profile
().
peer
.
domain_name
username
=
user
.
get_profile
().
peer
.
peer_tag
b
=
beanstalkc
.
Connection
()
b
.
use
(
settings
.
POLLS_TUBE
)
tube_message
=
json
.
dumps
({
'message'
:
messg
,
'username'
:
username
})
...
...
@@ -144,11 +191,6 @@ def check_sync(route_name=None, selected_routes = []):
if
route
.
status
!=
'ERROR'
:
logger
.
info
(
'Expiring %s route %s'
%
(
route
.
status
,
route
.
name
))
subtask
(
delete
).
delay
(
route
,
reason
=
"EXPIRED"
)
# elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'):
# route.status = 'EXPIRED'
# route.response = 'Rule Expired'
# logger.info('Expiring route %s' %route.name)
# route.save()
else
:
if
route
.
status
!=
'EXPIRED'
:
route
.
check_sync
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment