Class: Yes::Command::Api::Commands::Notifiers::ActionCable

Inherits:
Yes::Core::Commands::Notifier
  • Object
show all
Defined in:
lib/yes/command/api/commands/notifiers/action_cable.rb

Overview

Notifies command processing events via ActionCable broadcast. Used with an external WebSocket gateway (e.g. socket_gate).

Instance Method Summary collapse

Instance Method Details

#notify_batch_finished(batch_id, transaction = nil, responses = nil) ⇒ Object

Parameters:

  • batch_id (String)

    the id of the batch that has finished processing

  • transaction (TransactionDetails) (defaults to: nil)

    the transaction details

  • responses (Array<Response>) (defaults to: nil)

    the command responses



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/yes/command/api/commands/notifiers/action_cable.rb', line 29

def notify_batch_finished(batch_id, transaction = nil, responses = nil)
  ::ActionCable.server.broadcast(
    channel,
    {
      batch_id:,
      published_at:,
      type: 'batch_finished',
      transaction: transaction.to_h
    }.merge(failed_commands_data(responses))
  )
end

#notify_batch_started(batch_id, transaction = nil, commands = nil) ⇒ Object

Parameters:

  • batch_id (String)

    the id of the batch that has started processing

  • transaction (TransactionDetails) (defaults to: nil)

    the transaction details

  • commands (Array<Command>) (defaults to: nil)

    the commands being processed



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/yes/command/api/commands/notifiers/action_cable.rb', line 14

def notify_batch_started(batch_id, transaction = nil, commands = nil)
  ::ActionCable.server.broadcast(
    channel,
    {
      batch_id:,
      published_at:,
      type: 'batch_started',
      transaction: transaction.to_h
    }.merge(commands_data(commands))
  )
end

#notify_command_response(cmd_response) ⇒ Object

Parameters:

  • cmd_response (Yes::Core::Commands::Response)

    the command response



42
43
44
45
46
47
# File 'lib/yes/command/api/commands/notifiers/action_cable.rb', line 42

def notify_command_response(cmd_response)
  ::ActionCable.server.broadcast(
    channel,
    cmd_response.to_notification.merge(published_at:)
  )
end