0.02
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A simple interface for locking hardware resources available via ruby and backed by redis.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 4.0, >= 3.2
 Project Readme

Lock Manager

Build Status

Lock manager is designed to be a small helper gem that provides common methods for locking and unlocking hardware.

About

Lock manager is a simple gem designed to place a lock on a host via a json value in redis.

The format for the lock is

{"user":"stahnma","time":"2015-11-20 05:35:40 +0000",
"reason":"Because reasons"}

Usage

Create a lock manager object

a = LockManager.new(type: 'redis', server: 'localhost')

Check to see if the node is locked.

a.locked? 'pe-aix-72-builder'
=> false

Lock the node

a.lock 'pe-aix-72-builder', 'stahnma'
=> true

See the lock

a.show
=> "{\"user\":\"stahnma\",\"time\":\"2015-11-20 05:55:52 +0000\",\"reason\":null}"

Unlock the node

a.unlock 'pe-aix-72-builder', 'stahnma'
=> true

Lock with a purpose

 a.lock 'pe-aix-72-builder', 'stahnma', "Because I'm looking into a failure"
 => true

Ask for a lock, if node is already locked, keep trying and wait until you get one

a.polling_lock('pe-aix-72-builder', 'stahnma')
pe-aix-72-builder is locked...waiting 1 seconds.
pe-aix-72-builder is locked...waiting 2 seconds.
pe-aix-72-builder is locked...waiting 3 seconds.
pe-aix-72-builder is locked...waiting 5 seconds.
# Another operations elsewhere unlocked the node
=> true

Testing

Lock Manager now has tests and rubocop setup. There are basic tests for the functionality of lock manager.

Tests assume you have redis running on localhost on the default port.

bundle exec rake

License

Apache Sofware License 2.0