Project

marloss

0.01
No commit activity in last 3 years
No release in over 3 years
Distributed locking using AWS DynamoDB
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 12.3
~> 3.9
= 0.89.1

Runtime

 Project Readme

Marloss

Build Status Gem Version

Marloss is a general DynamoDB-based lock implementation.

rusty-lock

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.