Class: Dunlop::ExecutionBatchPid

Inherits:
Object
  • Object
show all
Defined in:
app/services/dunlop/execution_batch_pid.rb

Constant Summary collapse

PIDDIR =
Rails.root.join("tmp/pids")

Instance Method Summary collapse

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

#lockObject



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

Returns:

  • (Boolean)


19
20
21
# File 'app/services/dunlop/execution_batch_pid.rb', line 19

def locked?
  File.exist?(pidfile)
end