Sha256: d6e7cd15607b354ee5f84e28f9820b680d0fb0e753476f20108a63cc694dd5f3
Contents?: true
Size: 1.65 KB
Versions: 2
Compression:
Stored size: 1.65 KB
Contents
require 'mixlib/cli' require 'spanx/logger' require 'spanx/actor/collector' require 'spanx/actor/analyzer' require 'spanx/actor/log_reader' require 'spanx/actor/writer' require 'spanx/whitelist' require 'thread' # Spanx::Runner is initialized with a list of actors to run # and a config hash. It is then run to activate each actor # and join one of the running threads. # # Example: # Spanx::Runner.new("analyzer", {}).run # Spanx::Runner.new("analyzer", "writer", {}).run # # Valid actors are: # collector # analyzer # writer # log_reader # module Spanx class Runner attr_accessor :config, :queue, :actors def initialize(*args) @config = args.last.is_a?(Hash) ? args.pop : {} @queue = Queue.new validate_args!(args) @actors = args.map { |actor| self.send(actor.to_sym) } Daemonize.daemonize if config[:daemonize] STDOUT.sync = true if config[:debug] end def run threads = actors.map(&:run) threads.last.join end # actors def collector @collector ||= Spanx::Actor::Collector.new(config, queue) end def log_reader @log_reader ||= Spanx::Actor::LogReader.new(config[:access_log], queue, config[:log_reader][:tail_interval], whitelist) end def writer @writer ||= Spanx::Actor::Writer.new(config) end def analyzer @analyzer ||= Spanx::Actor::Analyzer.new(config) end # helpers def whitelist @whitelist ||= Spanx::Whitelist.new(config[:whitelist_file]) end private def validate_args!(args) raise("Invalid actor") unless (args - %w[collector log_reader writer analyzer]).empty? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spanx-0.1.1 | lib/spanx/runner.rb |
spanx-0.1.0 | lib/spanx/runner.rb |