Class: Yes::Command::Api::Commands::Notifiers::MessageBus
- Inherits:
-
Yes::Core::Commands::Notifier
- Object
- Yes::Core::Commands::Notifier
- Yes::Command::Api::Commands::Notifiers::MessageBus
- Defined in:
- lib/yes/command/api/commands/notifiers/message_bus.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ MessageBus
constructor
A new instance of MessageBus.
- #notify_batch_finished(batch_id, transaction = nil, responses = nil) ⇒ Object
- #notify_batch_started(batch_id, transaction = nil, commands = nil) ⇒ Object
- #notify_command_response(cmd_response) ⇒ Object
Constructor Details
#initialize(options) ⇒ MessageBus
Returns a new instance of MessageBus.
14 15 16 17 18 |
# File 'lib/yes/command/api/commands/notifiers/message_bus.rb', line 14 def initialize() super() @channel = [:channel] end |
Instance Method Details
#notify_batch_finished(batch_id, transaction = nil, responses = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/yes/command/api/commands/notifiers/message_bus.rb', line 41 def notify_batch_finished(batch_id, transaction = nil, responses = nil) user_ids = [transaction&.caller_id].compact data = { type: 'batch_finished', batch_id:, published_at: }.merge( transaction: transaction.to_h ).merge(failed_commands_data(responses)) ::MessageBus.publish(channel, data, user_ids: user_ids.empty? ? nil : user_ids) end |
#notify_batch_started(batch_id, transaction = nil, commands = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/yes/command/api/commands/notifiers/message_bus.rb', line 24 def notify_batch_started(batch_id, transaction = nil, commands = nil) user_ids = [transaction&.caller_id].compact data = { batch_id:, published_at:, type: 'batch_started' }.merge( transaction: transaction.to_h ).merge(commands_data(commands)) ::MessageBus.publish(channel, data, user_ids: user_ids.empty? ? nil : user_ids) end |
#notify_command_response(cmd_response) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/yes/command/api/commands/notifiers/message_bus.rb', line 57 def notify_command_response(cmd_response) user_ids = [cmd_response.transaction&.caller_id].compact ::MessageBus.publish( channel, cmd_response.to_notification.merge(published_at:), user_ids: user_ids.empty? ? nil : user_ids ) end |