Skip to content

Commit

Permalink
Fixing mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrenkenshu committed May 25, 2017
1 parent b449fa0 commit 85a3738
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_install:
install:
- bin/buildout -N
script:
- bin/nosetests
- bin/nosetests
after_success:
- bin/coveralls

30 changes: 13 additions & 17 deletions openprocurement/bot/identification/databridge/upload_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from gevent.hub import LoopExit
from restkit import ResourceError

from openprocurement.bot.identification.databridge.utils import journal_context, Data, create_file, RetryException
from openprocurement.bot.identification.databridge.utils import journal_context, Data, create_file
from openprocurement.bot.identification.databridge.journal_msg_ids import (
DATABRIDGE_SUCCESS_UPLOAD_TO_DOC_SERVICE, DATABRIDGE_UNSUCCESS_UPLOAD_TO_DOC_SERVICE,
DATABRIDGE_UNSUCCESS_RETRY_UPLOAD_TO_DOC_SERVICE, DATABRIDGE_SUCCESS_UPLOAD_TO_TENDER,
Expand Down Expand Up @@ -131,7 +131,6 @@ def retry_upload_to_doc_service(self):
extra=journal_context({"MESSAGE_ID": DATABRIDGE_UNSUCCESS_RETRY_UPLOAD_TO_DOC_SERVICE},
params={"TENDER_ID": tender_data.tender_id,
"ITEM_ID": tender_data.item_id, "DOCUMENT_ID": document_id}))
# self.retry_upload_to_doc_service_queue.put(tender_data)
gevent.sleep(0)

@retry(stop_max_attempt_number=5, wait_exponential_multiplier=1000)
Expand Down Expand Up @@ -161,23 +160,27 @@ def upload_to_tender(self):
tender_data.item_id))
except ResourceError as re:
if re.status_int == 422: # WARNING and don't retry
logger.warning("Accept 422, skip tender {} {} {} {}.".format(tender_data.tender_id,
logger.warning("Accept 422, skip tender {} {} {} {}. Message: {}".format(tender_data.tender_id,
tender_data.item_name,
tender_data.item_id, document_id),
tender_data.item_id, document_id, re.msg),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_422_UPLOAD_TO_TENDER},
{"TENDER_ID": tender_data.tender_id, "DOCUMENT_ID": document_id}))
self.update_processing_items(tender_data.tender_id, tender_data.item_id)
self.upload_to_tender_queue.get()
continue
elif re.status_int == 403:
logger.warning("Tender {} {} {} doc_id: {} changed status while processing and is no longer a valid target for the upload".format(
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id),
logger.warning("Accept 403 while uploading to tender {} {} {} doc_id: {}. Message {}".format(
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id, re.msg),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_ITEM_STATUS_CHANGED_WHILE_PROCESSING},
{"TENDER_ID": tender_data.tender_id, "DOCUMENT_ID": document_id})
)
self.update_processing_items(tender_data.tender_id, tender_data.item_id)
self.upload_to_tender_queue.get()
else:
logger.warning('Exception while retry uploading file to tender {} {} {} {}. Message: {}'.format(
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id, re.message),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_UNSUCCESS_RETRY_UPLOAD_TO_TENDER},
params={"TENDER_ID": tender_data.tender_id, "DOCUMENT_ID": document_id}))
self.retry_upload_to_tender_queue.put(tender_data)
self.upload_to_tender_queue.get()
except Exception as e:
Expand All @@ -201,31 +204,27 @@ def retry_upload_to_tender(self):
"""Get data from retry_upload_to_tender_queue; If upload was unsuccessful put Data obj back to
retry_upload_to_tender_queue"""
while not self.exit:
logger.info("Retry iteration to tender")
# import pdb; pdb.set_trace()
try:
tender_data = self.retry_upload_to_tender_queue.peek()
# import pdb; pdb.set_trace()
except LoopExit:
gevent.sleep(0)
continue
try:
document_id = tender_data.file_content.get('meta', {}).get('id')
self.client.headers.update({'X-Client-Request-ID': document_id})
self.client_upload_to_tender(tender_data)
# logger.info()
except ResourceError as re:
if re.status_int == 422: # WARNING and don't retry
logger.warning("Accept 422, skip tender {} {} {} {}.".format(tender_data.tender_id, tender_data.item_name,
tender_data.item_id, document_id),
logger.warning("Accept 422, skip tender {} {} {} {}. Message {}".format(tender_data.tender_id, tender_data.item_name,
tender_data.item_id, document_id, re.msg),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_422_UPLOAD_TO_TENDER},
{"TENDER_ID": tender_data.tender_id, "DOCUMENT_ID": document_id}))
self.update_processing_items(tender_data.tender_id, tender_data.item_id)
self.retry_upload_to_tender_queue.get()
continue
elif re.status_int == 403:
logger.warning("Tender {} {} {} doc_id: {} changed status while processing and is no longer a valid target for the upload".format(
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id),
logger.warning("Accept 403 while uploading to tender {} {} {} doc_id: {}. Message {}".format(
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id, re.msg),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_ITEM_STATUS_CHANGED_WHILE_PROCESSING},
{"TENDER_ID": tender_data.tender_id, "DOCUMENT_ID": document_id})
)
Expand All @@ -237,14 +236,12 @@ def retry_upload_to_tender(self):
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id, re.message),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_UNSUCCESS_RETRY_UPLOAD_TO_TENDER},
params={"TENDER_ID": tender_data.tender_id, "DOCUMENT_ID": document_id}))
# self.retry_upload_to_tender_queue.put(tender_data)
except Exception as e:
logger.info('Exception while retry uploading file to tender {} {} {} {}. Message: {}'.format(
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id, e.message),
extra=journal_context({"MESSAGE_ID": DATABRIDGE_UNSUCCESS_RETRY_UPLOAD_TO_TENDER},
params={"TENDER_ID": tender_data.tender_id, "DOCUMENT_ID": document_id}))
logger.exception(e)
# self.retry_upload_to_tender_queue.put(tender_data)
else:
logger.info('Successfully uploaded file to tender {} {} {} {} in retry'.format(
tender_data.tender_id, tender_data.item_name, tender_data.item_id, document_id),
Expand All @@ -259,7 +256,6 @@ def retry_upload_to_tender(self):
def client_upload_to_tender(self, tender_data):
"""Process upload to tender request for retry queue objects."""
document_data = tender_data.file_content.get('data', {})
logger.info("Trying to upload to tender")
document_data["documentType"] = "registerExtract"
self.client.headers.update({'X-Client-Request-ID': tender_data.file_content.get('meta', {}).get('id')})
self.client._create_tender_resource_item(munchify({'data': {'id': tender_data.tender_id}}),
Expand Down

0 comments on commit 85a3738

Please sign in to comment.