Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Small refactor to the
RedisLock
class.lock()
function calledraise_when_not_acquired
that raises an exception if the lock isn't acquired.TaskLock
class only optionally take aredis_client
parameter.Motivation and Context
This is a small refactor to attempt to DRY some uses of the
RedisLock
classes.Almost all the uses of
RedisLock
have the same pattern where they try to acquire the lock, then they raise (or exit) if the lock wasn't acquired. Since we are doing this everywhere anyway, this should be the default behavior. I addedraise_when_not_acquired
to do this, and refactored existing code to use it.Note: This changes the behavior of some tasks slightly. They used to silently exit if they couldn't acquire a lock, now they will exit with an error. Since we don't expect tasks to fail to get the lock, I think this is the correct thing to do, but it is a slight change.
The
TaskLock
class used to take a requiredredis_client
parameter. Since it also takes aTask
parameter, which has access to the redis client, we make it optional, and fall back to the redis client on the task.How Has This Been Tested?
Checklist