Class: FluQ::Worker

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Mixins::Loggable
Defined in:
lib/fluq/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Loggable

#logger

Constructor Details

#initialize(prefix, handlers = []) ⇒ Worker

Returns a new instance of Worker.

Parameters:

  • handlers (Array<Class,Array>) (defaults to: [])

    handler builders



9
10
11
12
13
14
15
16
17
# File 'lib/fluq/worker.rb', line 9

def initialize(prefix, handlers = [])
  @prefix   = prefix
  @handlers = []
  @observer = observe

  handlers.each do |klass, *args|
    add klass, *args
  end
end

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



6
7
8
# File 'lib/fluq/worker.rb', line 6

def handlers
  @handlers
end

#prefixObject (readonly)

Returns the value of attribute prefix.



6
7
8
# File 'lib/fluq/worker.rb', line 6

def prefix
  @prefix
end

Instance Method Details

#add(klass, *args) ⇒ Object

Adds a handler

Parameters:

  • klass (Class<FluQ::Handler::Base>)

    handler class

  • args (multiple)

    handler initialize arguments



31
32
33
34
35
# File 'lib/fluq/worker.rb', line 31

def add(klass, *args)
  handler = klass.new(*args)
  handlers.push handler
  handler
end

#process(events) ⇒ Object

Parameters:



20
21
22
23
24
25
26
# File 'lib/fluq/worker.rb', line 20

def process(events)
  events.freeze # Freeze events, don't allow individual handlers to modify them
  handlers.each do |handler|
    on_events(handler, Time.now, events)
  end
  true
end