Skip to content

Commit

Permalink
Discovery provider lock update + updated logs (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
hareeshnagaraj committed Mar 10, 2020
1 parent 0f5e653 commit 4632feb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions discovery-provider/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ def configure_celery(flask_app, celery, test_config=None):
# Initialize Redis connection
redis_inst = redis.Redis.from_url(url=redis_url)

# Clear existing lock if present
redis_inst.delete("disc_prov_lock")

# Initialize custom task context with database object
class DatabaseTask(Task):
def __init__(self, *args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions discovery-provider/src/tasks/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,15 @@ def update_task(self):
# Define lock acquired boolean
have_lock = False
# Define redis lock object
update_lock = redis.lock("disc_prov_lock", timeout=7200)
update_lock = redis.lock("disc_prov_lock", timeout=25, blocking_timeout=25)
try:
# Attempt to acquire lock - do not block if unable to acquire
have_lock = update_lock.acquire(blocking=False)
if have_lock:
# Refresh all IPFS peer connections
refresh_peer_connections(self)

logger.debug(f"index.py | update_task | Acquired disc_prov_lock")
logger.info(f"index.py | update_task | Acquired disc_prov_lock")
initialize_blocks_table_if_necessary(db)

latest_block = get_latest_block(db)
Expand Down Expand Up @@ -604,7 +604,7 @@ def update_task(self):
# Perform indexing operations
index_blocks(self, db, index_blocks_list)
else:
logger.info("index.py | update_task | Failed to acquire disc_prov_lock")
logger.error("index.py | update_task | Failed to acquire disc_prov_lock")
except Exception as e:
logger.error("Fatal error in main loop", exc_info=True)
raise e
Expand Down

0 comments on commit 4632feb

Please sign in to comment.