Class: Yes::Core::Commands::Bus

Inherits:
Object
  • Object
show all
Includes:
OpenTelemetry::Trackable
Defined in:
lib/yes/core/commands/bus.rb

Instance Method Summary collapse

Constructor Details

#initialize(command_processor: Processor, perform_inline: Yes::Core.configuration.process_commands_inline) ⇒ Bus

Returns a new instance of Bus.



12
13
14
15
16
17
18
# File 'lib/yes/core/commands/bus.rb', line 12

def initialize(
  command_processor: Processor,
  perform_inline: Yes::Core.configuration.process_commands_inline
)
  @command_processor = command_processor
  @perform_inline = perform_inline
end

Instance Method Details

#call(command_or_commands, origin: nil, notifier_options: {}, batch_id: nil) ⇒ void

This method returns an undefined value.

Passees commands on to the command processor, in case origin is not provided, it will be derived from the caller. Also decides based on config whether to perform commands inline or not

Parameters:

  • command_or_commands (Command, Array<Command>)

    Command(s) instance(s)

  • origin (String) (defaults to: nil)

    Origin of the command

  • notifier_options (Hash) (defaults to: {})

    Options for command notifier

  • batch_id (String) (defaults to: nil)

    Batch ID



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yes/core/commands/bus.rb', line 27

def call(
  command_or_commands,
  origin: nil,
  notifier_options: {},
  batch_id: nil
)
  origin ||= Utils::CallerUtils.origin_from_caller(caller_locations(1..1).first)

  perform_method = perform_inline ? :perform_now : :perform_later
  self.class.current_span&.add_attributes({ perform_method: perform_method.to_s, origin: }.stringify_keys)

  command_processor.public_send(
    perform_method, origin, command_or_commands, notifier_options, batch_id, perform_inline
  )
end