Marloss
Marloss is a general DynamoDB-based lock implementation.
This Gem is tested using Ruby 2.6, 2.5, 2.4
Installation
Add this line to your application's Gemfile:
gem "marloss"
And then execute:
$ bundle
Or install it yourself as:
$ gem install marloss
Usage
Marloss can be use as module, with some useful heplers, or plain for more specific use cases
Module
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
Plain
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
Testing
rspec
Logging
By default Marloss logs to STDOUT, you can override it with the following command.
Marloss.logger = Logger.new("my_app.log")
What's in a name?
"Marlòss" means lock, in Trentino's dialect. I'm from Volano, and I liked the idea of using a word from my hometown.
Contributing
This repository is open to contributions.