Class: MdbmDistSupport::Lock

Inherits:
Object
  • Object
show all
Includes:
CustomLogger
Defined in:
lib/mdbm_dist_support/lock.rb

Overview

Lockfile manager

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Lock

Returns a new instance of Lock.



10
11
12
# File 'lib/mdbm_dist_support/lock.rb', line 10

def initialize(path)
  @lock_file = open(path, 'w')
end

Instance Attribute Details

#lock_fileObject

Returns the value of attribute lock_file.



6
7
8
# File 'lib/mdbm_dist_support/lock.rb', line 6

def lock_file
  @lock_file
end

Instance Method Details

#try_lockObject



14
15
16
17
18
19
20
# File 'lib/mdbm_dist_support/lock.rb', line 14

def try_lock
  @lock_file.flock(File::LOCK_EX | File::LOCK_NB) || raise
  true
rescue
  @@logger.error "cannot get lock. #{@lock_file.path}"
  false
end