Class: Dunlop::ExecutionBatchPid
- Inherits:
-
Object
- Object
- Dunlop::ExecutionBatchPid
- Defined in:
- app/services/dunlop/execution_batch_pid.rb
Constant Summary collapse
- PIDDIR =
Rails.root.join("tmp/pids")
Instance Method Summary collapse
-
#initialize(id = nil) ⇒ ExecutionBatchPid
constructor
A new instance of ExecutionBatchPid.
- #lock ⇒ Object
- #locked? ⇒ Boolean
Constructor Details
#initialize(id = nil) ⇒ ExecutionBatchPid
Returns a new instance of ExecutionBatchPid.
5 6 7 |
# File 'app/services/dunlop/execution_batch_pid.rb', line 5 def initialize(id=nil) @id = id end |
Instance Method Details
#lock ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/services/dunlop/execution_batch_pid.rb', line 9 def lock raise "lock already taken" if locked? begin claim_lock yield ensure release_lock end end |
#locked? ⇒ Boolean
19 20 21 |
# File 'app/services/dunlop/execution_batch_pid.rb', line 19 def locked? File.exist?(pidfile) end |