Method: UniqueThread#run

Defined in:
lib/unique_thread.rb

#run(&block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/unique_thread.rb', line 41

def run(&block)
  safe_infinite_loop do
    lock = locksmith.new_lock

    if lock.acquired?
      self.class.logger.info('Lock acquired! Running the unique thread.')
      lock.while_held(&block)
    else
      self.class.logger.debug('Could not acquire the lock. Sleeping until next attempt.')
      stopwatch.sleep_until_next_attempt(lock.locked_until.to_f)
    end
  end
end