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
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
@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
-
- <<EOS
-Error: the sup index is locked by another process! User '#{e.user}' on
-host '#{e.host}' is running #{e.pname} with pid #{e.pid}. The process was alive
-as of #{time} ago.
-EOS
- end
-
- def lock_or_die
- begin
- lock
- rescue LockError => e
- $stderr.puts fancy_lock_error_message_for(e)
- $stderr.puts <<EOS
-
-You can wait for the process to finish, or, if it crashed and left a
-stale lock file behind, you can manually delete #{@lock.path}.
-EOS
- exit
- end
- end
-
def unlock
if @lock && @lock.locked?
- Redwood::log "unlocking #{lockfile}..."
+ debug "unlocking #{lockfile}..."
@lock.unlock
end
end
end
def save
- Redwood::log "saving index and sources..."
+ debug "saving index and sources..."
FileUtils.mkdir_p @dir unless File.exists? @dir
SourceManager.save_sources
save_index
unimplemented
end
- ## Syncs the message to the index, replacing any previous version. adding
- ## either way. Index state will be determined by the message's #labels
- ## accessor.
- def sync_message m, opts={}
- unimplemented
- end
+ def add_message m; unimplemented end
+ def update_message m; unimplemented end
+ def update_message_state m; unimplemented end
def save_index fn
unimplemented
end
index_name = ENV['SUP_INDEX'] || $config[:index] || DEFAULT_INDEX
-begin
- require "sup/#{index_name}_index"
-rescue LoadError
- fail "invalid index name #{index_name.inspect}"
+case index_name
+ when "xapian"; require "sup/xapian_index"
+ when "ferret"; require "sup/ferret_index"
+ else fail "unknown index type #{index_name.inspect}"
end
Index = Redwood.const_get "#{index_name.capitalize}Index"
-Redwood::log "using index #{Index.name}"
+debug "using index #{Index.name}"
end