Skip to content

Commit

Permalink
Implement Storage.release_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
joealcorn committed Aug 19, 2015
1 parent 1697494 commit f7b350e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion celery_dedupe/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ def obtain_lock(self, key, value):
Responsible for obtaining a lock for the task
:returns boolean: Whether lock could be obtained or not
'''
raise NotImplementedError
raise NotImplementedError('Storages must implement obtain_lock method')

def release_lock(self, key):
'''
Responsible for releasing a lock
'''
raise NotImplementedError('Storages must implement release_lock method')
2 changes: 2 additions & 0 deletions celery_dedupe/storage/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ def obtain_lock(self, key, value):

return obtained

def release_lock(self, key):
self.connection.delete(key)
7 changes: 7 additions & 0 deletions tests/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ def test_already_locked(self):
self.redis.setex(key, '1', 10)
storage = RedisStorage(self.redis, expiry=10)
assert not storage.obtain_lock(key, '1')

def test_release_lock(self):
key = uuid4()
self.redis.setex(key, '1', 10)
storage = RedisStorage(self.redis, expiry=10)
storage.release_lock(key)
assert not self.redis.get(key)

0 comments on commit f7b350e

Please sign in to comment.