Class: MdbmDistSupport::Lock
- Inherits:
-
Object
- Object
- MdbmDistSupport::Lock
- Includes:
- CustomLogger
- Defined in:
- lib/mdbm_dist_support/lock.rb
Overview
Lockfile manager
Instance Attribute Summary collapse
-
#lock_file ⇒ Object
Returns the value of attribute lock_file.
Instance Method Summary collapse
-
#initialize(path) ⇒ Lock
constructor
A new instance of Lock.
- #try_lock ⇒ Object
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_file ⇒ Object
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_lock ⇒ Object
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 |