Skip to content
Snippets Groups Projects
Commit 3d81ddfe authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #10339: applied patch from 2.19: when setting status and message, set...

Task #10339: applied patch from 2.19: when setting status and message, set status first and then message, otherwise mom can't handle it.
parent ed21376e
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,7 @@ class MoMClient: ...@@ -74,7 +74,7 @@ class MoMClient:
self.__logged_in = True self.__logged_in = True
except Exception as e: except Exception as e:
raise Exception("Logging into MoM failed: " + str(e)) raise Exception("Logging into MoM on %s failed: %s" % (self.__momURLlogin, str(e)))
def __logout(self): def __logout(self):
try: try:
...@@ -92,32 +92,60 @@ class MoMClient: ...@@ -92,32 +92,60 @@ class MoMClient:
def setStatus(self, export_id, status_id, message=None): def setStatus(self, export_id, status_id, message=None):
try: try:
if not self.__logged_in: # mom is quite reluctant in updating the status
self.__login() # often it returns a login page, even when you're logged in
# so, upon error, retry a couple of times with a pause, else just return
params = {"exportId" : export_id, "status" : status_id} for mom_retry in range(self.MAX_MOM_RETRIES):
if message: if not self.__logged_in:
if len(message) > 100: self.__login()
logger.info('truncating message to 100 characters because MoM cannot store more')
message = message[:97] + '...' params = {"exportId" : export_id, "status" : status_id}
statusUrl = self.__momURLsetStatus + '?' + urllib.urlencode(params)
params['message'] = message logger.debug("updating MoM: " + statusUrl)
response = self.__browser.open(statusUrl)
statusUrl = self.__momURLsetStatus + '?' + urllib.urlencode(params) reply = response.readlines()
logger.debug("updating MoM: " + statusUrl) if reply == ['ok']:
response = self.__browser.open(statusUrl) logger.info('MoMClient.setStatus updated status of %s to %s', export_id, jobState2String(int(status_id)))
reply = response.readlines()
if reply == ['ok']: if message:
logger.info('MoMClient.setStatus updated status of %s to %s', export_id, jobState2String(int(status_id))) # even though the mom api suggests that one could update the status and message at the same time
return True # this does not work. If the status changes, and there is a message, then the status is ignored.
else: # So, let's fool mom, and update the status again, this time including the message
logger.error('MoMClient.setStatus could not update status of %s to %s using url: %s reply: %s', # In this second call, the status won't change, because we already just changed it.
export_id, if len(message) > 100:
jobState2String(int(status_id)), logger.info('truncating message to 100 characters because MoM cannot store more')
statusUrl, message = message[:97] + '...'
reply)
self.__logout() params['message'] = message
return False
statusUrl = self.__momURLsetStatus + '?' + urllib.urlencode(params)
logger.debug("updating MoM: " + statusUrl)
response = self.__browser.open(statusUrl)
reply = response.readlines()
if reply == ['ok']:
logger.info('MoMClient.setStatus updated status of %s to %s with message: %s',
export_id,
jobState2String(int(status_id)),
message)
# if the message update did not succeed, we don't really care
# the status update already succeeded, and that's important.
return True
else:
logger.error('MoMClient.setStatus could not update status of %s to %s using url: %s reply: %s',
export_id,
jobState2String(int(status_id)),
statusUrl,
reply)
self.__logout()
if 'DOCTYPE HTML PUBLIC' in reply:
logger.error('MoM returned login screen instead of SIP for archive_id=%s mom_id=%s using url %s and data %s', archive_id, mom_id, self.__momURLgetSIP, data)
wait_secs = (mom_retry+1)*(mom_retry+1)*10
logger.info('Retrying to setStatus for archiveId %s in %s seconds', archive_id, wait_secs)
time.sleep(wait_secs)
continue #jump back to for mom_retry in range(self.MAX_MOM_RETRIES)
except Exception as e: except Exception as e:
logger.error('MoMClient.setStatus could not update status of %s to %s: %s', export_id, logger.error('MoMClient.setStatus could not update status of %s to %s: %s', export_id,
jobState2String(int(status_id)), jobState2String(int(status_id)),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment