lib/qtrix/locking.rb
##
# Attempts to obtain a global qtrix lock and if its obtained,
# execute the passed block of code.  If the lock is held by
# another, this will either block for a time (specified with
# the timeout option) to gain the lock and then fail with a
# timeout exception, or it will immediately return a result
# passed from the caller (via the on_timeout callable option).
#
# By default this uses a 10 second timeout.
Attempts to obtain a global qtrix lock and if its obtained,
execute the passed block of code.  If the lock is held by
another, this will either block for a time (specified with
the timeout option) to gain the lock and then fail with a
timeout exception, or it will immediately return a result
passed from the caller (via the on_timeout callable option).

By default this uses a 10 second timeout.
Attempts to obtain a global qtrix lock and if its obtained execute the passed block of code . If the lock is held by another this will either block for a time ( specified with the timeout option ) to gain the lock and then fail with a timeout exception or it will immediately return a result passed from the caller ( via the on_timeout callable option ) . By default this uses a 10 second timeout .
def with_lock(opts={}, &block)
      result = nil
      start_time = Time.now.to_i
      timeout_duration = opts[:timeout] || DEFAULT_TIMEOUT
      on_timeout = opts[:on_timeout] || lambda{ raise Timeout }
      loop do
        if aquire_lock
          result = invoke_then_release_lock(&block)
          break
        elsif we_have_timed_out(start_time, timeout_duration)
          debug("failed to aquire lock in #{timeout_duration}")
          result = on_timeout.call
          break
        end
        sleep(0.1)
      end
      result
    end
def with_lock ( opts = { } , & block ) result = nil start_time = Time . now . to_i timeout_duration = opts [ :timeout ] || DEFAULT_TIMEOUT on_timeout = opts [ :on_timeout ] || lambda { raise Timeout } loop do if aquire_lock result = invoke_then_release_lock ( & block ) break elsif we_have_timed_out ( start_time , timeout_duration ) debug ( "failed to aquire lock in #{timeout_duration}" ) result = on_timeout . call break end sleep ( 0.1 ) end result end
Attempts to obtain a global qtrix lock and if its obtained,
execute the passed block of code.
Attempts to obtain a global qtrix lock and if its obtained execute the passed block of code .
opts
<not_specific>
block
<not_specific>