module ProcessBalancer::Lock::SimpleRedis
This is a simple implementation of a lock to ensure only one job runner is running for a worker This is only save for a single redis instance setup something more resilient should be used instead, e.g. and advisory lock in a DB or using RedLock ( github.com/leandromoreira/redlock-rb )
Public Class Methods
time_source()
click to toggle source
# File lib/process_balancer/lock/simple_redis.rb, line 10 def self.time_source @time_source ||= if defined?(Process::CLOCK_MONOTONIC) proc { (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i } else proc { (Time.now.to_f * 1000).to_i } end end
Public Instance Methods
worker_lock() { |lock| ... }
click to toggle source
# File lib/process_balancer/lock/simple_redis.rb, line 65 def worker_lock lock = LockHandler.new("lock_#{job_id}_#{worker_index}", ProcessBalancer.identity, runtime_lock_timeout) lock.acquire! if lock.acquired? begin yield lock ensure lock.release! end end end