-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor RedisLock (PP-1481) #2285
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2285 +/- ##
=======================================
Coverage 91.12% 91.12%
=======================================
Files 363 363
Lines 41330 41333 +3
Branches 8846 8846
=======================================
+ Hits 37660 37663 +3
Misses 2408 2408
Partials 1262 1262 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. 🎸
Just one minor typo in a comment.
assert not acquired | ||
|
||
# If the raise_when_not_acquired parameter is set, the context manager raises | ||
# an exception is the lock is not acquired. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo here: "...[if] the lock..."
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