Skip to content

Commit

Permalink
Merge branch 'cache-lazydb'
Browse files Browse the repository at this point in the history
Conflicts:
	openprocurement/contracting/api/databridge.py
  • Loading branch information
vmaksymiv committed Jun 3, 2016
2 parents 955505b + 3943490 commit 9e8bb1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion openprocurement/contracting/api/databridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
logger = logging.getLogger("openprocurement.contracting.api.databridge")
# logger = logging.getLogger(__name__)

from lazydb import Db

db = Db('databridge_cache_db')


def generate_req_id():
return b'contracting-data-bridge-req-' + str(uuid4()).encode('ascii')
Expand Down Expand Up @@ -143,7 +147,11 @@ def get_tender_contracts(self):
if contract["status"] == "active":

try:
self.contracting_client.get_contract(contract['id'])
if not db.has(contract['id']):
self.contracting_client.get_contract(contract['id'])
else:
logger.info('Contract {} exists in local db'.format(contract['id']), extra={"CONTRACT_ID": contract['id']})
continue
except ResourceNotFound:
logger.info('Sync contract {} of tender {}'.format(contract['id'], tender['id']), extra={"CONTRACT_ID": contract['id'],
"TENDER_ID": tender['id']})
Expand All @@ -153,6 +161,7 @@ def get_tender_contracts(self):
self.tenders_queue.put(tender_to_sync)
break
else:
db.put(contract['id'], True)
logger.info('Contract exists {}'.format(contract['id']), extra={"CONTRACT_ID": contract['id']})
continue

Expand Down Expand Up @@ -218,6 +227,7 @@ def put_contracts(self):
self.contracting_client.create_contract(data)
logger.info("Successfully created contract {} of tender {}".format(contract['id'], contract['tender_id']),
extra={"CONTRACT_ID": contract['id'], "TENDER_ID": contract['tender_id']})
db.put(contract['id'], True)
except Exception, e:
logger.exception(e)
logger.info("Unsuccessful put for contract {0} of tender {1}".format(contract['id'], contract['tender_id']),
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os

version = '2.3.1'
version = '2.3.3dev1'

requires = [
'couchdb',
Expand All @@ -20,6 +20,7 @@
databridge_requires = requires + [
'PyYAML',
'gevent',
'LazyDB',
'ExtendedJournalHandler',
'openprocurement_client>=1.0b2'
]
Expand Down

0 comments on commit 9e8bb1e

Please sign in to comment.