Sha256: 002e72f7cd3d407d2a4bfb1bae569f1dc913201c17dd02d640264ec123352210

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'digest/md5'

class FluQ::Handler::Base
  include FluQ::Mixins::Loggable

  # @return [String] handler type
  def self.type
    @type ||= name.split("::")[-1].downcase
  end

  # @attr_reader [String] name unique name
  attr_reader :name

  # @attr_reader [Hash] config
  attr_reader :config

  # @param [Hash] options
  # @option options [String] :name a (unique) handler identifier
  # @example
  #
  #   class MyHandler < FluQ::Handler::Base
  #   end
  #   MyHandler.new
  #
  def initialize(options = {})
    @config  = defaults.merge(options)
    @name    = config[:name] || self.class.type
  end

  # @param [Array<FluQ::Event>] events
  # @return [Array<FluQ::Event>] filtered events
  def filter(events)
    events
  end

  # @return [Timers] timers
  def timers
    @timers ||= Timers.new
  end

  # @abstract callback, called on each event
  # @param [Array<FluQ::Event>] the event stream
  def on_events(events)
  end

  protected

    # Configuration defaults
    def defaults
      { timeout: 60 }
    end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluq-0.8.1 lib/fluq/handler/base.rb
fluq-0.8.0 lib/fluq/handler/base.rb