Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/a231215749783594_reinit_contract…
Browse files Browse the repository at this point in the history
…ing_clients_on_error'
  • Loading branch information
vmaksymiv committed Dec 21, 2016
2 parents 607545d + fbebcc3 commit 9ab7459
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions openprocurement/contracting/api/databridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,8 @@ def __init__(self, config):
self.contracts_retry_put_queue = Queue(maxsize=queue_size)
self.basket = {}

def clients_initialize(self):
self.client = TendersClient(
self.config_get('api_token'),
host_url=self.api_server, api_version=self.api_version,
)

def contracting_client_init(self):
logger.info('Initialization contracting clients.', extra=journal_context({"MESSAGE_ID": DATABRIDGE_INFO}, {}))
self.contracting_client = ContractingClient(
self.config_get('api_token'),
host_url=self.contracting_api_server, api_version=self.contracting_api_version
Expand All @@ -150,6 +146,15 @@ def clients_initialize(self):
'',
host_url=self.ro_api_server, api_version=self.api_version
)

def clients_initialize(self):
self.client = TendersClient(
self.config_get('api_token'),
host_url=self.api_server, api_version=self.api_version,
)

self.contracting_client_init()

self.tenders_sync_client = TendersClientSync('',
host_url=self.ro_api_server, api_version=self.api_version,
)
Expand Down Expand Up @@ -266,7 +271,7 @@ def _get_tender_contracts(self):
logger.info('Put tender {} back to tenders queue'.format(tender_to_sync['id']), extra=journal_context({"MESSAGE_ID": DATABRIDGE_EXCEPTION}, params={"TENDER_ID": tender_to_sync['id'],
"CONTRACT_ID": contract['id']}))
self.tenders_queue.put(tender_to_sync)
break
raise
else:
self.cache_db.put(contract['id'], True)
logger.info('Contract exists {}'.format(contract['id']), extra=journal_context({"MESSAGE_ID": DATABRIDGE_CONTRACT_EXISTS},
Expand Down Expand Up @@ -324,6 +329,7 @@ def get_tender_contracts(self):
logger.warn("Fail to handle tender contracts", extra=journal_context({"MESSAGE_ID": DATABRIDGE_EXCEPTION}, {}))
logger.exception(e)
gevent.sleep(self.on_error_delay)
raise
gevent.sleep(0)

def prepare_contract_data(self):
Expand Down Expand Up @@ -525,6 +531,8 @@ def run(self):
for name, job in self.immortal_jobs.items():
if job.dead:
logger.warn('Restarting {} worker'.format(name))
if name == 'get_tender_contracts':
self.contracting_client_init()
self.immortal_jobs[name] = gevent.spawn(getattr(self, name))

except KeyboardInterrupt:
Expand Down

0 comments on commit 9ab7459

Please sign in to comment.