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: 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: