Class: Trailblazer::Macro::Nested::Dynamic

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/macro/nested.rb

Constant Summary collapse

SUCCESS_SEMANTICS =

TODO: make this injectable/or get it from operation.

[:success, :pass_fast]

Class Method Summary collapse

Class Method Details

.call_dynamic_nested_activity(ctx, flow_options, runner:, **circuit_options) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/trailblazer/macro/nested.rb', line 86

def self.call_dynamic_nested_activity((ctx, flow_options), runner:, **circuit_options)
  nested_activity       = flow_options[:decision]
  original_flow_options = flow_options.slice(*(flow_options.keys - [:decision]))

  host_activity = Dynamic.host_activity_for(activity: nested_activity)

  # TODO: make activity here that has only one step (plus In and Out config) which is {nested_activity}

  return_signal, (ctx, flow_options) = runner.(
    nested_activity,
    [ctx, original_flow_options], # pass {flow_options} without a {:decision}.
    runner:   runner,
    **circuit_options,
    activity: host_activity
  )

  return compute_legacy_return_signal(return_signal), [ctx, flow_options]
end

.compute_legacy_return_signal(return_signal) ⇒ Object



105
106
107
108
# File 'lib/trailblazer/macro/nested.rb', line 105

def self.compute_legacy_return_signal(return_signal)
  actual_semantic  = return_signal.to_h[:semantic]
  applied_signal   = SUCCESS_SEMANTICS.include?(actual_semantic) ? Activity::Right : Activity::Left # TODO: we could also provide PassFast/FailFast.
end

.host_activity_for(activity:) ⇒ Object

This is used in Nested and Each where some tasks don’t have a corresponding, hard-wired activity. This is needed for TaskWrap.invoke and the Debugging API in tracing.



113
114
115
116
117
118
# File 'lib/trailblazer/macro/nested.rb', line 113

def self.host_activity_for(activity:)
  Activity::TaskWrap.container_activity_for(
    activity,
    id: activity.to_s
  )
end