Class: Ec2::Lock

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/ec2/lock.rb

Instance Method Summary collapse

Methods included from Logger

#debug?, #logger, logger, #stderr, stderr

Instance Method Details

#acquireObject



7
8
9
10
11
# File 'lib/ec2/lock.rb', line 7

def acquire
  logger.debug "acquiring lock"
  lock_acquired = lock_file.flock(File::LOCK_NB | File::LOCK_EX)
  raise "exclusive lock not available" if not lock_acquired
end

#lock_fileObject



13
14
15
# File 'lib/ec2/lock.rb', line 13

def lock_file
  @lock_file ||= File.open(".ec2.lock", "a+")
end