Skip to content

Commit

Permalink
Merge pull request #344 from treviza153/bugfix/CheckingLock
Browse files Browse the repository at this point in the history
Adding get cached info validation
  • Loading branch information
treviza153 authored Aug 18, 2021
2 parents c8098eb + 8684564 commit 3d14080
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions networkapi/distributedlock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 5 additions & 0 deletions networkapi/distributedlock/memcachedlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions networkapi/util/geral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3d14080

Please sign in to comment.