LIKE US FOR UPDATES + GET A FREE STICKER PACK!

Operation

Activity API

Last updated 13 September 2017 trailblazer-activity v0.2

Trace

To track the path of a running activity (also called trailing) along with the variables before and after each task, use tracing.

Tracing works with any level of nesting. Please consider this simple example.

activity = Activity.from_hash do |start, _end|
  {
    start            => { Activity::Right => Blog::Write },
    Blog::Write      => { Activity::Right => Blog::SpellCheck },
    Blog::SpellCheck => { Activity::Right => Blog::Publish, Activity::Left => Blog::Correct },
    Blog::Correct    => { Activity::Right => Blog::SpellCheck },
    Blog::Publish    => { Activity::Right => _end }
  }
end

Instead of calling the activity directly, let the Trace module take care of setting up tracing and call the activity via Trace.call.

stack, _ = Trailblazer::Activity::Trace.( activity,
  [
    { content: "Let's start writing" }
  ]
)

All arguments to Trace.call are directly passed to the activity’s call.

Internally, tracing is implemented by adding two steps to every task’s task wrap: one before and one after task_wrap.call_task. These will store various data, such as the runtime data going in and out of the task.

Note that you could also invoke tracing only for selected tasks, in case you want to debug some specific part, only (we will add docs shortly).

Trace: Present

The Trace.call method returns a Stack instance, followed by the original return values of the activity’s call.

To quickly visualize the traced path, use Present.tree.

puts Trailblazer::Activity::Trace::Present.tree(stack)
 |--> #<Start: default {}>{:content=>"Let's start writing"}
 |--> Blog::Write{:content=>"Let's start writing"}
 |--> Blog::SpellCheck{:content=>"Let's start writing"}
 |--> Blog::Publish{:content=>"Let's start writing"}
 `--> #<End: default {}>{:content=>"Let's start writing"}

This prints a more or less cryptic representation of the path the activity took.

In future versions, tracing will also display variables with improved configurability. This will be added very very shortly.

Very soon, you can debug your code in real-time visually using the PRO editor.