Class: Karafka::Web::Pro::Commanding::Dispatcher
- Inherits:
-
Object
- Object
- Karafka::Web::Pro::Commanding::Dispatcher
- Defined in:
- lib/karafka/web/pro/commanding/dispatcher.rb
Overview
Dispatcher for sending commanding related messages. Those can be: - command (do something) - result (you wanted me to get you some info, here it is)
Dispatcher requires Web UI to have a producer
Constant Summary collapse
- SCHEMA_VERSION =
What schema do we have in current Karafka version for commands dispatches
'1.1.0'
Class Method Summary collapse
-
.acceptance(command_name, process_id, params = {}) ⇒ Object
Dispatches the acceptance info.
-
.request(command_name, process_id, params = {}) ⇒ Object
Dispatches the command request.
-
.result(command_name, process_id, result) ⇒ Object
Dispatches the result request.
Class Method Details
.acceptance(command_name, process_id, params = {}) ⇒ Object
Dispatches the acceptance info. Indicates that a command was received and appropriate action will be taken but async. Useful for commands that may not take immediate actions upon receiving a command.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 50 def acceptance(command_name, process_id, params = {}) produce( process_id, 'acceptance', { schema_version: SCHEMA_VERSION, type: 'acceptance', command: params.merge(name: command_name), dispatched_at: Time.now.to_f, process: { id: process_id } } ) end |
.request(command_name, process_id, params = {}) ⇒ Object
Dispatches the command request
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 26 def request(command_name, process_id, params = {}) produce( process_id, 'request', { schema_version: SCHEMA_VERSION, type: 'request', # Name is auto-generated and required. Should not be changed command: params.merge(name: command_name), dispatched_at: Time.now.to_f, process: { id: process_id } } ) end |
.result(command_name, process_id, result) ⇒ Object
Dispatches the result request
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/karafka/web/pro/commanding/dispatcher.rb', line 71 def result(command_name, process_id, result) produce( process_id, 'result', { schema_version: SCHEMA_VERSION, type: 'result', command: { name: command_name }, result: result, dispatched_at: Time.now.to_f, process: { id: process_id } } ) end |