class JustOneLock::BaseLocker

Public Instance Methods

already_locked(scope) click to toggle source
# File lib/just_one_lock/base_locker.rb, line 2
def already_locked(scope)
  msg = "Another process <#{scope}> already is running"
  JustOneLock.puts msg
  raise JustOneLock::AlreadyLocked, msg
end

Private Instance Methods

run(f, path, &block) click to toggle source
# File lib/just_one_lock/base_locker.rb, line 17
def run(f, path, &block)
  write_pid(f)

  JustOneLock.before_lock(path, f)
  result = block.call
  JustOneLock.after_lock(path, f)

  result
end
write_pid(f) click to toggle source
# File lib/just_one_lock/base_locker.rb, line 10
def write_pid(f)
  f.rewind
  f.write(Process.pid)
  f.flush
  f.truncate(f.pos)
end