Sha256: 23c4231221d64fc5f812f8183f3aa2221d9ecb3aa50a511aeb4d69099e8d8e0e
Contents?: true
Size: 1.27 KB
Versions: 9
Compression:
Stored size: 1.27 KB
Contents
# vim:fileencoding=utf-8 module ResqueAdmin module Scheduler module Lock class Base attr_reader :key attr_accessor :timeout def initialize(key, options = {}) @key = key # 3 minute default timeout @timeout = options[:timeout] || 60 * 3 end # Attempts to acquire the lock. Returns true if successfully acquired. def acquire! raise NotImplementedError end def value @value ||= [hostname, process_id].join(':') end # Returns true if you currently hold the lock. def locked? raise NotImplementedError end # Releases the lock. def release! ResqueAdmin.redis.del(key) == 1 end # Releases the lock iff we own it def release locked? && release! end private # Extends the lock by `timeout` seconds. def extend_lock! ResqueAdmin.redis.expire(key, timeout) end def hostname local_hostname = Socket.gethostname Socket.gethostbyname(local_hostname).first rescue local_hostname end def process_id Process.pid end end end end end
Version data entries
9 entries across 9 versions & 2 rubygems