Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
1abae87e
Commit
1abae87e
authored
5 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
SW-699
: proper use of exceptions in handling message
parent
b631a2f9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/lib/ingestmomadapter.py
+31
-37
31 additions, 37 deletions
...IngestServer/LTAIngestAdminServer/lib/ingestmomadapter.py
with
31 additions
and
37 deletions
LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/lib/ingestmomadapter.py
+
31
−
37
View file @
1abae87e
...
...
@@ -70,20 +70,17 @@ class IngestEventMessageHandlerForMomAdapter(IngestEventMessageHandler):
try
:
# try 'normal' handling of msg, should result in normal calls to onJob* methods
# but MoM (via the momrpc) is notorious in properly handling the messages....
if
super
(
IngestEventMessageHandlerForMomAdapter
,
self
).
handle_message
(
msg
):
return
True
super
().
handle_message
(
msg
)
except
Exception
as
e
:
# ... so handle the exceptions...
logger
.
warning
(
e
)
# ... and try to deal with MoM's quirks.
if
self
.
_remove_unknown_export_job_if_needed
(
msg
):
return
True
if
self
.
_resubmit_message_if_applicable
(
msg
):
return
True
# ... and try to deal with MoM's quirks.
if
self
.
_remove_unknown_export_job_if_needed
(
msg
):
return
True
return
False
if
self
.
_resubmit_message_if_applicable
(
msg
):
return
True
def
onJobStarted
(
self
,
job_dict
):
self
.
_update_mom_status_if_applicable
(
job_dict
,
JobProducing
)
...
...
@@ -208,34 +205,31 @@ class IngestEventMessageHandlerForMomAdapter(IngestEventMessageHandler):
return
False
def
_resubmit_message_if_applicable
(
self
,
msg
:
EventMessage
)
->
bool
:
try
:
if
msg
and
msg
.
content
:
retry_count
=
msg
.
content
.
get
(
'
retry_count
'
,
0
)
if
retry_count
<
min
(
MAX_NR_OF_RETRIES
,
127
):
# mom can't handle more than 127 status updates...
retry_count
+=
1
try
:
retry_timestamp
=
msg
.
content
.
get
(
'
retry_timestamp
'
,
datetime
.
utcnow
())
ago
=
totalSeconds
(
datetime
.
utcnow
()
-
retry_timestamp
)
time
.
sleep
(
max
(
0
,
2
*
retry_count
-
ago
))
# wait longer between each retry, other messages can be processed in between
except
Exception
as
e
:
# just continue
logger
.
warning
(
e
)
# set/update retry values
msg
.
content
[
'
retry_count
'
]
=
retry_count
msg
.
content
[
'
retry_timestamp
'
]
=
datetime
.
utcnow
()
# resubmit
new_msg
=
EventMessage
(
subject
=
msg
.
subject
,
content
=
msg
.
content
)
new_msg
.
ttl
=
48
*
3600
# remove message from queue's when not picked up within 48 hours
logger
.
info
(
'
resubmitting unhandled message to back of queue %s: %s %s
'
,
self
.
exchange
,
new_msg
.
subject
,
str
(
new_msg
.
content
).
replace
(
'
\n
'
,
'
'
))
self
.
_tobus
.
send
(
new_msg
)
return
True
except
Exception
as
e
:
logger
.
error
(
"
_resubmit_message_if_applicable error: %s
"
,
e
)
if
msg
and
msg
.
content
:
retry_count
=
msg
.
content
.
get
(
'
retry_count
'
,
0
)
if
retry_count
<
min
(
MAX_NR_OF_RETRIES
,
127
):
# mom can't handle more than 127 status updates...
retry_count
+=
1
try
:
retry_timestamp
=
msg
.
content
.
get
(
'
retry_timestamp
'
,
datetime
.
utcnow
())
ago
=
totalSeconds
(
datetime
.
utcnow
()
-
retry_timestamp
)
time
.
sleep
(
max
(
0
,
2
*
retry_count
-
ago
))
# wait longer between each retry, other messages can be processed in between
except
Exception
as
e
:
# just continue
logger
.
warning
(
e
)
# set/update retry values
msg
.
content
[
'
retry_count
'
]
=
retry_count
msg
.
content
[
'
retry_timestamp
'
]
=
datetime
.
utcnow
()
# resubmit
new_msg
=
EventMessage
(
subject
=
msg
.
subject
,
content
=
msg
.
content
)
new_msg
.
ttl
=
48
*
3600
# remove message from queue's when not picked up within 48 hours
logger
.
info
(
'
resubmitting unhandled message to back of queue %s: %s %s
'
,
self
.
exchange
,
new_msg
.
subject
,
str
(
new_msg
.
content
).
replace
(
'
\n
'
,
'
'
))
self
.
_tobus
.
send
(
new_msg
)
return
True
return
False
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment