From 0576567439317b45cf2a42032701b4e28ca46684 Mon Sep 17 00:00:00 2001 From: "marcus.vinicius" Date: Wed, 17 Mar 2021 15:25:31 -0300 Subject: [PATCH 1/2] remove localhost (127.0.0.1) from netapi_app container for remote access --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index de67ad1de..ddc5d21bb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,8 +56,8 @@ services: image: globocom/networkapi:latest restart: always ports: - - "127.0.0.1:8000:8000" - - "127.0.0.1:8001:8001" + - "8000:8000" + - "8001:8001" env_file: - scripts/docker/netapi.env volumes: From 8684564bb5cdf75ddefafb61ea94db8529530e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20J=C3=BAnior?= Date: Wed, 18 Aug 2021 18:52:19 -0300 Subject: [PATCH 2/2] adding get cached info validation --- networkapi/distributedlock/__init__.py | 3 +++ networkapi/distributedlock/memcachedlock.py | 5 +++++ networkapi/util/geral.py | 3 +++ 3 files changed, 11 insertions(+) diff --git a/networkapi/distributedlock/__init__.py b/networkapi/distributedlock/__init__.py index 388237095..692988f40 100644 --- a/networkapi/distributedlock/__init__.py +++ b/networkapi/distributedlock/__init__.py @@ -117,3 +117,6 @@ def __enter__(self): def __exit__(self, type, value, traceback): _debug('releasing lock %s' % self.key) self.lock.release() + + def get_cached_data(self): + return self.lock.get_cached_data() diff --git a/networkapi/distributedlock/memcachedlock.py b/networkapi/distributedlock/memcachedlock.py index 8f29f45a0..ad3e426d3 100644 --- a/networkapi/distributedlock/memcachedlock.py +++ b/networkapi/distributedlock/memcachedlock.py @@ -69,3 +69,8 @@ def release(self): else: log.warning( "I've no lock to release. Increase TIMEOUT of lock operations") + + def get_cached_data(self): + value = self.client.get(self.key) + + return value if value else None diff --git a/networkapi/util/geral.py b/networkapi/util/geral.py index d364f104f..e8d68342f 100644 --- a/networkapi/util/geral.py +++ b/networkapi/util/geral.py @@ -72,6 +72,9 @@ def create_lock_with_blocking(locks_name): for lock_name in locks_name: try: lock = distributedlock(lock_name, blocking=False) + if lock.get_cached_data(): + log.info('Get cached lock data for {}. Disabling it and creating a new lock'.format(lock_name)) + lock.__exit__('', '', '') lock.__enter__() locks_list.append(lock) except LockNotAcquiredError: