Marloss is a general DynamoDB-based lock implementation.
This Gem is tested using Ruby 2.6, 2.5, 2.4
Add this line to your application's Gemfile:
gem "marloss"
And then execute:
$ bundle
Or install it yourself as:
$ gem install marloss
Marloss can be use as module, with some useful heplers, or plain for more specific use cases
Include the module to your class and set the options
class MyClass
include Marloss
marloss_options table: "my_table", hash_key: "ID"
end
now you can simply wrap the code that needs to be locked
with_marloss_locker("my_lock") do |locker|
# execute code
# ...
# refresh lock if needed
locker.refresh
end
Firstly, we need to initialize a lock store:
store = Marloss::Store.new("lock_table_name", "LockHashKeyName")
Create table if it does not exist:
store.create_table
We can use this store to create a single lock
locker = Marloss::Locker.new(store, "my_resource")
# raise exception if we fail to get a lock
locker.obtain_lock
# or we can block until we get a lock
locker.wait_until_lock_obtained
# refresh the lock once
locker.refresh_lock
# delete the lock
locker.release_lock
rspec
By default Marloss logs to STDOUT, you can override it with the following command.
Marloss.logger = Logger.new("my_app.log")
"Marlòss" means lock, in Trentino's dialect. I'm from Volano, and I liked the idea of using a word from my hometown.
This repository is open to contributions.