Sha256: ea231de82fa01c5414ebb368b0accf941e20485d463d8840fdfcc03fb3b2b81a
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
# Locker subsystem module Locker # Label helpers module Label def label(name) redis.hgetall("label_#{name}") end def labels redis.keys('label_*') end def label_exists?(name) redis.exists("label_#{name}") end def lock_label!(name, owner, time_until) return false unless label_exists?(name) key = "label_#{name}" members = label_membership(name) members.each do |m| return false unless lock_resource!(m, owner, time_until) end redis.hset(key, 'state', 'locked') redis.hset(key, 'owner_id', owner.id) redis.hset(key, 'until', time_until) true end def unlock_label!(name) return false unless label_exists?(name) key = "label_#{name}" members = label_membership(name) members.each do |m| unlock_resource!(m) end redis.hset(key, 'state', 'unlocked') redis.hset(key, 'owner_id', '') true end def create_label(name) label_key = "label_#{name}" redis.hset(label_key, 'state', 'unlocked') unless resource_exists?(name) || label_exists?(name) end def delete_label(name) label_key = "label_#{name}" redis.del(label_key) if label_exists?(name) end def label_membership(name) redis.smembers("membership_#{name}") end def add_resource_to_label(label, resource) return unless label_exists?(label) && resource_exists?(resource) redis.sadd("membership_#{label}", resource) end def remove_resource_from_label(label, resource) return unless label_exists?(label) && resource_exists?(resource) redis.srem("membership_#{label}", resource) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lita-locker-0.7.0 | lib/locker/label.rb |