X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Findex.rb;h=ff03f195f6bca74aefdb23eedecc01c2172ee39c;hb=46f8e5116f38c8248fdc8553db18f8d2132a1f46;hp=fb46eb053a02b871923e93281021441414e11683;hpb=fa5a06c2904ff4c9cb266d4a9df2b35efa0433e5;p=sup diff --git a/lib/sup/index.rb b/lib/sup/index.rb index fb46eb0..ff03f19 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -6,13 +6,15 @@ begin require 'chronic' $have_chronic = true rescue LoadError => e - Redwood::log "optional 'chronic' library not found (run 'gem install chronic' to install)" + debug "optional 'chronic' library not found; date-time query restrictions disabled" $have_chronic = false end module Redwood class BaseIndex + include InteractiveLock + class LockError < StandardError def initialize h @h = h @@ -26,13 +28,12 @@ class BaseIndex def initialize dir=BASE_DIR @dir = dir @lock = Lockfile.new lockfile, :retries => 0, :max_age => nil - self.class.i_am_the_instance self end def lockfile; File.join @dir, "lock" end def lock - Redwood::log "locking #{lockfile}..." + debug "locking #{lockfile}..." begin @lock.lock rescue Lockfile::MaxTriesLockError @@ -54,45 +55,9 @@ class BaseIndex @lock_update_thread = nil end - def possibly_pluralize number_of, kind - "#{number_of} #{kind}" + - if number_of == 1 then "" else "s" end - end - - def fancy_lock_error_message_for e - secs = (Time.now - e.mtime).to_i - mins = secs / 60 - time = - if mins == 0 - possibly_pluralize secs , "second" - else - possibly_pluralize mins, "minute" - end - - < e - $stderr.puts fancy_lock_error_message_for(e) - $stderr.puts <