class Wayfarer::CrawlObserver

Attributes

logger[R]

Public Class Methods

new(*observables, logger) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 29
def initialize(*observables, logger)
  @logger = logger
  observables.each { |obsv| obsv.add_observer(self) }
end

Public Instance Methods

update(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 34
def update(event)
  case event
  when Events::FirstCycle     then first_cycle(event)
  when Events::NewCycle       then new_cycle(event)
  when Events::DispatchedURI  then dispatched_uri(event)
  when Events::CycleFinished  then cycle_finished
  when Events::Peeking        then peeking(event)
  when Events::AboutToCycle   then about_to_cycle(event)
  when Events::MismatchedURI  then mismatched_uri(event)
  when Events::HaltInitiated  then halt_initiated(event)
  when Events::StagingURIs    then staging_uris(event)
  when Events::UnhandledError then unhandled_error(event)
  end
end

Private Instance Methods

about_to_cycle(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 72
def about_to_cycle(event)
  logger.info("About to cycle. #{event.staged_uris_count} staged URI(s)")
end
cycle_finished() click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 64
def cycle_finished
  logger.info("No URIs left in current cycle")
end
dispatched_uri(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 60
def dispatched_uri(event)
  logger.info("Dispatched to \##{event.action}: #{event.uri}")
end
first_cycle(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 51
def first_cycle(event)
  logger.info("First cycle")
  logger.info("Frontier: #{event.frontier}")
end
halt_initiated(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 80
def halt_initiated(event)
  logger.info("Halt initiated from \##{event.action} at: #{event.uri}")
end
mismatched_uri(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 76
def mismatched_uri(event)
  logger.debug("No matching route for: #{event.uri}")
end
new_cycle(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 56
def new_cycle(event)
  logger.info("Current cycle contains #{event.current_uris_count} URI(s)")
end
peeking(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 68
def peeking(event)
  logger.info("Peeking into: #{event.uri}")
end
staging_uris(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 84
def staging_uris(event)
  logger.info("Staging #{event.staged_uris_count} URI(s)")
end
unhandled_error(event) click to toggle source
# File lib/wayfarer/crawl_observer.rb, line 88
    def unhandled_error(event)
      level = config.reraise_exceptions ? :fatal : :error

      if config.print_stacktraces
        logger.public_send level, <<~LOGGER
          Unhandled exception in an action: #{event.exception.class.inspect}
          #{event.exception.backtrace.map(&:to_s).join("\n* ")}
        LOGGER
      else
        logger.public_send level, <<~LOGGER
          Unhandled exception in an action: #{event.exception.class.inspect}
        LOGGER
      end
    end