module Trailblazer::Activity::TaskWrap
Example with tracing:
Call the task_wrap circuit:
|-- Start |-- Trace.capture_args [optional] |-- Call (call actual task) id: "task_wrap.call_task" |-- Trace.capture_return [optional] |-- Wrap::End
Private Class Methods
call_task(wrap_ctx, original_args)
click to toggle source
TaskWrap
step that calls the actual wrapped task and passes all `original_args` to it.
It writes to wrap_ctx, wrap_ctx
# File lib/trailblazer/activity/task_wrap/call_task.rb, line 6 def self.call_task(wrap_ctx, original_args) task = wrap_ctx[:task] original_arguments, original_circuit_options = original_args # Call the actual task we're wrapping here. # puts "~~~~wrap.call: #{task}" return_signal, return_args = task.(original_arguments, **original_circuit_options) # DISCUSS: do we want original_args here to be passed on, or the "effective" return_args which are different to original_args now? wrap_ctx = wrap_ctx.merge( return_signal: return_signal, return_args: return_args ) return wrap_ctx, original_args end
wrap_static_for(task, activity:, **)
click to toggle source
Retrieve the static wrap config from {activity}.
# File lib/trailblazer/activity/task_wrap/runner.rb, line 47 def self.wrap_static_for(task, activity:, **) wrap_static = activity[:wrap_static] wrap_static[task] or raise "#{task}" end
Private Instance Methods
Extension(merge:)
click to toggle source
Use this in your macros if you want to extend the {taskWrap}.
# File lib/trailblazer/activity/task_wrap.rb, line 40 def Extension(merge:) Extension.new(merge: Pipeline::Merge.new(*merge)) end
initial_wrap_static(*)
click to toggle source
{:extension} API Extend the static taskWrap from a macro or DSL call. Gets executed in {Intermediate.call} which also provides {config}.
# File lib/trailblazer/activity/task_wrap.rb, line 34 def initial_wrap_static(*) # return initial_sequence TaskWrap::Pipeline.new([["task_wrap.call_task", TaskWrap.method(:call_task)]]) end
invoke(activity, args, wrap_runtime: {}, wrap_static: initial_wrap_static, **circuit_options)
click to toggle source
Compute runtime arguments necessary to execute a taskWrap per task of the activity. This method is the top-level entry, called only once for the entire activity graph.
# File lib/trailblazer/activity/task_wrap.rb, line 17 def invoke(activity, args, wrap_runtime: {}, wrap_static: initial_wrap_static, **circuit_options) circuit_options = circuit_options.merge( runner: TaskWrap::Runner, wrap_runtime: wrap_runtime, # This {:activity} structure is currently (?) only needed in {TaskWrap.wrap_static_for}, where we # access {activity[:wrap_static]} to compile the effective taskWrap. activity: {wrap_static: {activity => wrap_static}, nodes: {}}, # for Runner. Ideally we'd have a list of all static_wraps here (even nested). ) # signal, (ctx, flow), circuit_options = Runner.(activity, args, **circuit_options) end