Class: Textus::Infra::Refresh::Lock
- Inherits:
-
Object
- Object
- Textus::Infra::Refresh::Lock
- Defined in:
- lib/textus/infra/refresh/lock.rb
Instance Method Summary collapse
-
#initialize(root:, key:) ⇒ Lock
constructor
A new instance of Lock.
- #release ⇒ Object
-
#try_acquire ⇒ Object
rubocop:disable Naming/PredicateMethod.
Constructor Details
Instance Method Details
#release ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/textus/infra/refresh/lock.rb', line 28 def release return unless @file @file.flock(File::LOCK_UN) @file.close @file = nil end |
#try_acquire ⇒ Object
rubocop:disable Naming/PredicateMethod
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/textus/infra/refresh/lock.rb', line 14 def try_acquire # rubocop:disable Naming/PredicateMethod FileUtils.mkdir_p(File.dirname(@path)) @file = File.open(@path, File::RDWR | File::CREAT, 0o644) acquired = @file.flock(File::LOCK_EX | File::LOCK_NB) unless acquired @file.close @file = nil return false end @file.write(Process.pid.to_s) @file.flush true end |