Hyrax is a Ruby on Rails Engine built by the Samvera community. Hyrax provides a foundation for creating many different digital repository applications.
Allows callers of LockManager#lock and Lockable#acquire_lock_for to optionally pass in ttl, retry_count, and/or retry_delay parameters that will override the lock manager configuration for that particular lock request.
Type of change (for release notes)
notes-minor New Features that are backward compatible
Detailed Description
LockManager#lock now optionally takes ttl, retry_count, and retry_delay keyword arguments, which override the configured values for that lock request only, e.g.
lock_manager.lock(some_key, ttl: 5000) do # overrides default ttl of 60,000 ms
some_operation
end
The same applies to Lockable#acquire_lock_for:
class SomeTask
include Hyrax::Lockable
def perform
acquire_lock_for(some_key, retry_delay: 30) do # overrides default delay of 30 ms
some_operation
end
end
private
def some_operation
# ...
end
end
The default behavior of LockManager and Lockable haven't changed.
Notes
Currently, in this PR, LockManager#lock explicitly declares ttl, retry_count, and retry_delay keyword parameters. An alternative approach would be to just take ttl (which is passed to Redlock::Client#lock) and an arbitrary hash of Redlock client options (of which retry_count and retry_delay are just two possible values). I decided not to go that direction because:
these are the only parameters we thought were worth configuring
there's been some discussion of getting off Redlock (and Redis), and I didn't want to tie us too closely to that API
I did, however, redefine Lockable#acquire_lock_for to be a simple delegate to lock_manager.lock -- that's how it was behaving anyway, and it seemed cleaner than re-declaring the parameters there. I've implemented it with Forwardable, but if we think that's too cute, we could instead do something like:
def acquire_lock_for(key, **kwargs, &block)
lock_manager.lock(key, **kwargs, &block)
end
Results for commit 5b0ddc95. ± Comparison against base commit a8ae9539.
This pull request removes 267 and adds 278 tests. Note that renamed tests count towards both.
```
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy AdminSet: fbce70ad-6a49-4e8d-b673-d23238fe5a02
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy Hyrax::AdministrativeSet: 942a61e8-4a2a-4094-8fb9-659447408952
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to edit AdminSet: 336e86e3-7ed5-47fc-bddb-a95a41d84c55
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to edit Hyrax::AdministrativeSet: 945b3161-72c1-4ca7-874f-54a87ce907db
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to update AdminSet: 01cea523-4b49-4c9d-afbe-f4ac70ec871a
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to update Hyrax::AdministrativeSet: 4fa5fe66-e99a-488d-85e9-edad73b6e48b
…
```
```
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy AdminSet: 25aa604e-d5d5-4195-a3c7-913aff818ee1
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy Hyrax::AdministrativeSet: a54900bc-03c6-4248-9a77-cde0154f683b
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to edit AdminSet: 5a1d5748-9217-4471-b745-c500fc70d795
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to edit Hyrax::AdministrativeSet: 945be7f6-c67e-4a05-815e-7b1a7ce186f6
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to update AdminSet: 8bc1e65c-64c6-46a1-9171-1b7cbb6ee764
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to update Hyrax::AdministrativeSet: 3c6c839e-b3c3-4812-abda-af95e4d562ca
…
```
Fixes
Fixes #6947.
Summary
Allows callers of
LockManager#lock
andLockable#acquire_lock_for
to optionally pass inttl
,retry_count
, and/orretry_delay
parameters that will override the lock manager configuration for that particular lock request.Type of change (for release notes)
notes-minor
New Features that are backward compatibleDetailed Description
LockManager#lock
now optionally takesttl
,retry_count
, andretry_delay
keyword arguments, which override the configured values for that lock request only, e.g.The same applies to
Lockable#acquire_lock_for
:The default behavior of
LockManager
andLockable
haven't changed.Notes
Currently, in this PR,
LockManager#lock
explicitly declaresttl
,retry_count
, andretry_delay
keyword parameters. An alternative approach would be to just takettl
(which is passed toRedlock::Client#lock
) and an arbitrary hash of Redlock client options (of whichretry_count
andretry_delay
are just two possible values). I decided not to go that direction because:I did, however, redefine
Lockable#acquire_lock_for
to be a simple delegate tolock_manager.lock
-- that's how it was behaving anyway, and it seemed cleaner than re-declaring the parameters there. I've implemented it withForwardable
, but if we think that's too cute, we could instead do something like:@samvera/hyrax-code-reviewers