anchor.diff:  %%% @end
   %%%-------------------------------------------------------------------
   %%% @doc
  -%%% This module provides utility functions for management of automation
  -%%% workflow execution status and phase.
  +%%% This module contains functions that handle atm workflow execution status
  +%%% transitions according to following state machine:
  +%%%
  +%%%  W
  +%%%  A         +-----------+
  +%%%  I         | SCHEDULED |------------------------------
  +%%%  T         +-----------+                               \
  +%%%  I               |                                      |
  +%%%  N    first lane run transitions                        |
  +%%%  G        to preparing status                           |
  +%%%                  |                                      |
  +%%% =================|======================================|=================
  +%%%                  v                                      |
  +%%%            +-----------+                                |
  +%%%            |   ACTIVE  |--------------------------------o
  +%%%            +-----------+                                |
  +%%%                       \                    currently executed lane run
  +%%%                        \                     failed or was cancelled
  +%%%  O                      \                               |
  +%%%  N                       \                              v
  +%%%  G                        \                       +-----------+
  +%%%  O                         \                      |  ABORTING |
  +%%%  I                          \                     +-----------+
  +%%%  N                           \                  /
  +%%%  G                        last executed lane run
  +%%%                          /          |           \
  +%%%                         /           |            \
  +%%%                        /            |             \
  +%%%         successfully finished     failed      was cancelled
  +%%%                      /              |                \
  +%%% ====================/===============|=================\===================
  +%%%                    /                |                  \
  +%%%  E                v                 v                   v
  +%%%  N     +-----------+           +-----------+           +-----------+
  +%%%  D     |  FINISHED |           |   FAILED  |           | CANCELLED |
  +%%%  E     +-----------+           +-----------+           +-----------+
  +%%%  D
  +%%%
  +%%% Note: When transition to ended phase occurs the workflow execution status is
  +%%% copied from last executed lane run which works because:
  +%%% 1) if last lane run successfully finished than all previous lane runs must
  +%%%    have also successfully finished.
  +%%% 2) if last lane run aborted (due to cancel or failure) than entire workflow
  +%%%    execution is aborted with the same reason.
   %%% @end
   %%%-------------------------------------------------------------------
   -module(atm_workflow_execution_status).
  
positive.code: -spec handle_lane_aborting(
      undefined | pos_integer(),
      atm_workflow_execution:id(),
      fun((atm_workflow_execution:record()) -> atm_workflow_execution:record() | errors:error())
  ) ->
      ok | errors:error().
  handle_lane_aborting(AtmLaneIndex, AtmWorkflowExecutionId, AtmLaneExecutionDiff) ->
      Diff = fun
          (Record = #atm_workflow_execution{status = Status, curr_lane_index = CurrIndex}) when
              Status == ?SCHEDULED_STATUS;
              Status == ?ACTIVE_STATUS;
              Status == ?ABORTING_STATUS
          ->
              IsCurrentlyExecutedLane = AtmLaneIndex == undefined orelse AtmLaneIndex == CurrIndex,
  
              case {IsCurrentlyExecutedLane, AtmLaneExecutionDiff(Record)} of
                  {true, {ok, NewRecord}} ->
                      {ok, set_times_on_phase_transition(NewRecord#atm_workflow_execution{
                          status = ?ABORTING_STATUS
  
negative.code:     end.
  
  
  -spec handle_lane_enqueued(atm_workflow_execution:id(), lane_run_diff()) ->
      {ok, atm_workflow_execution:doc()} | errors:error().
  handle_lane_enqueued(AtmWorkflowExecutionId, AtmLaneExecutionDiff) ->
      atm_workflow_execution:update(AtmWorkflowExecutionId, fun
  