class Procrastinate::Lock

A file based lock below a base directory that is identified by Lock.base.

Attributes

base[RW]

Base directory for all lock files that are created.

file[R]
name[R]

Public Class Methods

new(name) click to toggle source
# File lib/procrastinate/lock.rb, line 13
def initialize(name)
  @name = name
  @file = File.open(
    File.join(
      self.class.base, name), 
    'w+')
end

Public Instance Methods

acquire() click to toggle source
# File lib/procrastinate/lock.rb, line 21
def acquire
  file.flock File::LOCK_EX
end
release() click to toggle source
# File lib/procrastinate/lock.rb, line 24
def release
  file.flock File::LOCK_UN
end
synchronize() { || ... } click to toggle source
# File lib/procrastinate/lock.rb, line 28
def synchronize
  acquire
  yield
ensure 
  release
end