Module: Mumukit::Nuntius::TaskConsumer
- Included in:
- EventConsumer, JobConsumer
- Defined in:
- lib/mumukit/nuntius/task_consumer.rb
Defined Under Namespace
Classes: Builder
Instance Method Summary collapse
- #handle(&block) ⇒ Object
- #handle_tasks!(properties, body) ⇒ Object
- #handled_tasks ⇒ Object
- #handlers ⇒ Object
- #handles?(task) ⇒ Boolean
- #log_exception(task, e, body) ⇒ Object
- #log_unknown_task(task) ⇒ Object
- #register_handlers!(handlers) ⇒ Object
- #start! ⇒ Object
Instance Method Details
#handle(&block) ⇒ Object
33 34 35 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 33 def handle(&block) register_handlers! builder.new.tap { |it| it.instance_eval(&block) }.build end |
#handle_tasks!(properties, body) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 56 def handle_tasks!(properties, body) return if skip_process? body task = properties[:type] if handles? task handlers[task].call body[:data].except(:sender) else log_unknown_task task end rescue => e log_exception(task, e, body[:data]) end |
#handled_tasks ⇒ Object
37 38 39 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 37 def handled_tasks handlers.keys end |
#handlers ⇒ Object
29 30 31 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 29 def handlers @@handlers ||= {} end |
#handles?(task) ⇒ Boolean
52 53 54 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 52 def handles?(task) handlers.include? task end |
#log_exception(task, e, body) ⇒ Object
72 73 74 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 72 def log_exception(task, e, body) Mumukit::Nuntius::Logger.error "Failed to proccess #{task}, error was: #{e}, body was: #{body}" end |
#log_unknown_task(task) ⇒ Object
68 69 70 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 68 def log_unknown_task(task) Mumukit::Nuntius::Logger.info "Unhandled #{task_type}: #{task} does not exists." end |
#register_handlers!(handlers) ⇒ Object
41 42 43 |
# File 'lib/mumukit/nuntius/task_consumer.rb', line 41 def register_handlers!(handlers) @@handlers = handlers end |