Class: EventHub::Processor2
- Inherits:
-
Object
- Object
- EventHub::Processor2
- Includes:
- Helper
- Defined in:
- lib/eventhub/processor2.rb
Overview
Processor2 class
Constant Summary collapse
- SIGNALS_FOR_TERMINATION =
[:INT, :TERM, :QUIT]
- SIGNALS_FOR_RELOAD_CONFIG =
[:HUP]
- ALL_SIGNALS =
SIGNALS_FOR_TERMINATION + SIGNALS_FOR_RELOAD_CONFIG
Instance Attribute Summary collapse
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
Instance Method Summary collapse
- #after_stop ⇒ Object
- #before_start ⇒ Object
-
#handle_message(_message, _args = {}) ⇒ Object
get message as EventHub::Message class instance args contain :queue_name, :content_type, :priority, :delivery_tag.
-
#initialize(args = {}) ⇒ Processor2
constructor
A new instance of Processor2.
-
#publish(args = {}) ⇒ Object
pass message as string like: ‘{ “header”: … , “body”: { .. }}’ and optionally exchange_name: ‘your exchange name’.
- #start ⇒ Object
- #stop ⇒ Object
- #version ⇒ Object
Methods included from Helper
#create_bunny_connection, #get_name_from_class, #now_stamp, #stringify_keys
Constructor Details
#initialize(args = {}) ⇒ Processor2
Returns a new instance of Processor2.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/eventhub/processor2.rb', line 15 def initialize(args = {}) # Set processor name EventHub::Configuration.name = args[:name] || get_name_from_class(self) # Parse comand line options EventHub::Configuration. # Load configuration file EventHub::Configuration.load!(args) @command_queue = [] @sleeper = EventHub::Sleeper.new @started_at = Time.now @statistics = EventHub::Statistics.new end |
Instance Attribute Details
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
13 14 15 |
# File 'lib/eventhub/processor2.rb', line 13 def started_at @started_at end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
13 14 15 |
# File 'lib/eventhub/processor2.rb', line 13 def statistics @statistics end |
Instance Method Details
#after_stop ⇒ Object
73 74 75 |
# File 'lib/eventhub/processor2.rb', line 73 def after_stop # can be implemented in derived class end |
#before_start ⇒ Object
69 70 71 |
# File 'lib/eventhub/processor2.rb', line 69 def before_start # can be implemented in derived class end |
#handle_message(_message, _args = {}) ⇒ Object
get message as EventHub::Message class instance args contain :queue_name, :content_type, :priority, :delivery_tag
56 57 58 |
# File 'lib/eventhub/processor2.rb', line 56 def (, _args = {}) raise "need to be implemented in derived class" end |
#publish(args = {}) ⇒ Object
pass message as string like: ‘{ “header”: … , “body”: { .. }}’ and optionally exchange_name: ‘your exchange name’
62 63 64 65 66 67 |
# File 'lib/eventhub/processor2.rb', line 62 def publish(args = {}) Celluloid::Actor[:actor_listener].publish(args) rescue => error EventHub.logger.error("Unexpected exeption while publish: #{error}") raise end |
#start ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/eventhub/processor2.rb', line 33 def start EventHub.logger.info("#{Configuration.name} (#{version}): has been started") before_start main_event_loop after_stop EventHub.logger.info("#{Configuration.name} (#{version}): has been stopped") rescue => ex EventHub.logger.error("Unexpected error in Processor2.start: #{ex}") end |
#stop ⇒ Object
45 46 47 48 |
# File 'lib/eventhub/processor2.rb', line 45 def stop # used by rspec @command_queue << :TERM end |