Module: SolidObjects::Transmission

Defined in:
lib/solid_objects/transmission.rb,
sig/generated/lib/solid_objects/transmission.rbs

Constant Summary collapse

REQUIRED_FIELDS =

Returns:

  • (Object)
%w[effectId actorType actorId operation].freeze
IDEMPOTENCY_PREFIX =

Returns:

  • (::String)
"transmit:"
EFFECT_NAME =

Returns:

  • (::String)
"solid-objects.transmit"
UNDELIVERED_STATUSES =

Returns:

  • (Object)
%w[pending processing].freeze

Class Method Summary collapse

Class Method Details

.deliver_through(effect_name:, arguments:, context:, deliver:) ⇒ nil

RBS:

  • (effect_name: String, arguments: Hash[String, untyped], context: EffectContext, deliver: Proc) -> nil

Parameters:

  • effect_name: (String)
  • arguments: (Hash[String, untyped])
  • context: (EffectContext)
  • deliver: (Proc)

Returns:

  • (nil)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/solid_objects/transmission.rb', line 32

def deliver_through(effect_name:, arguments:, context:, deliver:)
  staged_envelope(
    arguments,
    effect_id: context.id,
    actor_type: context.actor_type,
    actor_id: context.actor_id
  )
  undelivered_envelopes_through(effect_name:, context:).each do |envelope|
    deliver.call(envelope)
  end
  nil
end

.receive(envelope, resolve_actor_type: :itself.to_proc, mailbox: Mailbox.new, actor_loader: method(:load_application_actors)) ⇒ MessageReference

RBS:

  • (untyped envelope, ?resolve_actor_type: ^(String) -> (String | Symbol), ?mailbox: Mailbox, ?actor_loader: ^() -> bool) -> MessageReference

Parameters:

  • envelope (Object)
  • resolve_actor_type: (^(String) -> (String | Symbol)) (defaults to: :itself.to_proc)
  • mailbox: (Mailbox) (defaults to: Mailbox.new)
  • actor_loader: (^() -> bool) (defaults to: method(:load_application_actors))

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/solid_objects/transmission.rb', line 12

def receive(envelope, resolve_actor_type: :itself.to_proc, mailbox: Mailbox.new, actor_loader: method(:load_application_actors))
  validate!(envelope)

  actor_type = resolve_actor_type.call(envelope["actorType"]).to_s
  actor_class = fetch_actor_class(actor_type, actor_loader)
  operation = envelope["operation"].to_sym
  unless actor_class.definition.messages.key?(operation)
    raise UnknownMessage, "unknown operation #{envelope["operation"].inspect}"
  end

  mailbox.enqueue(
    reference: Reference.new(actor_type:, actor_id: envelope["actorId"]),
    operation:,
    arguments: envelope.fetch("arguments", {}),
    delivery_mode: "internal",
    idempotency_key: "#{IDEMPOTENCY_PREFIX}#{envelope["effectId"]}"
  )
end