Method: TreasureData::Updater::ModuleDefinition#wait_for_lock

Defined in:
lib/td/updater.rb

#wait_for_lock(path, wait_for = 5, check_every = 0.5) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/td/updater.rb', line 83

def wait_for_lock(path, wait_for = 5, check_every = 0.5)
  start = Time.now.to_i
  while File.exists?(path)
    sleep check_every
    if (Time.now.to_i - start) > wait_for
      raise_error "Unable to acquire update lock"
    end
  end
  begin
    FileUtils.touch(path)
    ret = yield
  ensure
    FileUtils.rm_f(path)
  end
  ret
end