Method: Chef::RunLock#acquire

Defined in:
lib/chef/run_lock.rb

#acquireObject

Acquire the system-wide lock. Will block indefinitely if another process already has the lock and Chef::Config[:run_lock_timeout] is not set. Otherwise will block for Chef::Config[:run_lock_timeout] seconds and exit if the lock is not acquired.

Each call to acquire should have a corresponding call to #release.

The implementation is based on File#flock (see also: flock(2)).

Either acquire() or test() methods should be called in order to get the ownership of run_lock.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/chef/run_lock.rb', line 64

def acquire
  if timeout_given?
    begin
      Timeout.timeout(time_to_wait) do
        unless test
          if time_to_wait > 0.0
            wait
          else
            exit_from_timeout
          end
        end
      end
    rescue Timeout::Error
      exit_from_timeout
    end
  else
    wait unless test
  end
end