Class: ProcessManager

Inherits:
Object show all
Defined in:
lib/crazy_ivan/process_manager.rb

Constant Summary collapse

@@lockfile =
Lockfile.new('/tmp/crazy_ivan.lock', :retries => 1)

Class Method Summary collapse

Class Method Details

.acquire_lock!Object



12
13
14
15
16
17
# File 'lib/crazy_ivan/process_manager.rb', line 12

def self.acquire_lock!
  lock
  yield
ensure
  unlock
end

.lockObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/crazy_ivan/process_manager.rb', line 24

def self.lock
  Syslog.debug "Acquiring lock"
  @@lockfile.lock
  Syslog.debug("Locked CI process")
rescue Lockfile::LockError
  msg = "Detected another running CI process - cannot start"
  Syslog.warning msg
  puts msg
  raise AlreadyRunningError, msg
end

.lockfilepath=(filepath) ⇒ Object



8
9
10
# File 'lib/crazy_ivan/process_manager.rb', line 8

def self.lockfilepath=(filepath)
  @@lockfile = Lockfile.new(filepath, :retries => 1)
end

.unlockObject



19
20
21
22
# File 'lib/crazy_ivan/process_manager.rb', line 19

def self.unlock
  @@lockfile.unlock
rescue Lockfile::UnLockError
end