Skip to content

Commit

Permalink
Merge pull request #74 from gorserg/format_logger_warning
Browse files Browse the repository at this point in the history
format logger warning message
  • Loading branch information
kroman0 committed Sep 29, 2016
2 parents 0936f0a + 1490481 commit 23729f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions openprocurement/tender/competitivedialogue/databridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import argparse
import copy
from restkit.errors import ResourceError

from retrying import retry
from uuid import uuid4
Expand All @@ -36,7 +37,7 @@
DATABRIDGE_CD_PATCHED_STAGE2_ID, DATABRIDGE_PATCH_NEW_TENDER_STATUS, DATABRIDGE_SUCCESSFUL_PATCH_NEW_TENDER_STATUS,
DATABRIDGE_UNSUCCESSFUL_PATCH_NEW_TENDER_STATUS, DATABRIDGE_PATCH_DIALOG_STATUS,
DATABRIDGE_UNSUCCESSFUL_PATCH_DIALOG_STATUS, DATABRIDGE_SUCCESSFUL_PATCH_DIALOG_STATUS, DATABRIDGE_ONLY_PATCH,
DATABRIDGE_TENDER_STAGE2_NOT_EXIST, DATABRIDGE_CREATE_NEW_STAGE2)
DATABRIDGE_TENDER_STAGE2_NOT_EXIST, DATABRIDGE_CREATE_NEW_STAGE2, DATABRIDGE_WORKER_DIED)


dialog_work = set() # local storage for current competitive dialogue in main queue
Expand Down Expand Up @@ -316,15 +317,28 @@ def put_tender_stage2(self):
data = {"data": new_tender}
try:
res = self.client.create_tender(data)
except Exception, e:
logger.exception(e)
except ResourceError as re:
if re.status_int == 412: # Update Cookie, and retry
self.client.headers['Cookie'] = re.response.headers['Set-Cookie']
elif re.status_int == 422: # WARNING and don't retry
logger.warn("Catch 422 status, stop create tender stage2",
extra=journal_context({"MESSAGE_ID": DATABRIDGE_UNSUCCESSFUL_CREATE},
{"TENDER_ID": new_tender['dialogueID']}))
continue
elif re.status_int == 404: # WARNING and don't retry
logger.warn("Catch 404 status, stop create tender stage2",
extra=journal_context({"MESSAGE_ID": DATABRIDGE_UNSUCCESSFUL_CREATE},
{"TENDER_ID": new_tender['dialogueID']}))
continue
logger.info("Unsuccessful put for tender stage2 of competitive dialogue id={0}".format(new_tender['dialogueID']),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_UNSUCCESSFUL_CREATE},
{"TENDER_ID": new_tender['dialogueID']}))
logger.info("Schedule retry for competitive dialogue id={0}".format(new_tender['dialogueID']),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_RETRY_CREATE},
{"TENDER_ID": new_tender['dialogueID']}))
self.dialogs_stage2_retry_put_queue.put(new_tender)
except Exception, e:
logger.exception(e)
else:
logger.info("Successfully created tender stage2 id={} from competitive dialogue id={}".format(res['data']['id'], res['data']['dialogueID']),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_TENDER_CREATED},
Expand Down Expand Up @@ -528,7 +542,7 @@ def get_competitive_dialogue_forward(self):
self.competitive_dialogues_queue.put(tender_data)
except Exception, e:
# TODO reset queues and restart sync
logger.warn('Forward worker died!')
logger.warn('Forward worker died!', extra=journal_context({"MESSAGE_ID": DATABRIDGE_WORKER_DIED}, {}))
logger.exception(e)
else:
logger.warn('Forward data sync finished!') # Should never happen!!!
Expand All @@ -544,7 +558,7 @@ def get_competitive_dialogue_backward(self):
self.competitive_dialogues_queue.put(tender_data)
except Exception, e:
# TODO reset queues and restart sync
logger.warn('Backward worker died!')
logger.warn('Backward worker died!', extra=journal_context({"MESSAGE_ID": DATABRIDGE_WORKER_DIED}, {}))
logger.exception(e)
else:
logger.info('Backward data sync finished.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
DATABRIDGE_ONLY_PATCH = 'cd_bridge_need_patch'
DATABRIDGE_TENDER_STAGE2_NOT_EXIST = 'cd_bridge_tender_stage2_not_exist'
DATABRIDGE_CREATE_NEW_STAGE2 = 'cd_bridge_create_new_tender_stage2'

DATABRIDGE_WORKER_DIED = 'cd_bridge_worker_died'

0 comments on commit 23729f3

Please sign in to comment.