Sha256: 6389ce3c674eb97871d23d327d77df112d74a0dbe29849186c2a08af32731754
Contents?: true
Size: 551 Bytes
Versions: 20
Compression:
Stored size: 551 Bytes
Contents
require 'diplomat' module Shipitron module ConsulLock extend self class UnableToLock < StandardError; end def with_lock(key:) sessionid = nil locked = false sessionid = Diplomat::Session.create(Name: "#{key}.lock") locked = Diplomat::Lock.acquire(key, sessionid) if locked yield else raise UnableToLock end ensure if sessionid != nil Diplomat::Lock.release(key, sessionid) if locked Diplomat::Session.destroy(sessionid) end end end end
Version data entries
20 entries across 20 versions & 1 rubygems