getStep - noetl/noetl GitHub Wiki

E.g. exitCode = getStep(taskInstance, branchInstance)

Parameters

  • task: task object associated with the current step and branch
  • branch: current branch object

Key Variables

  • step: current step instance
  • exitCode: associated with the success or fail of the step
  • delStep: delete step; step to delete from task.links to prevent loops in the links map
  • delNext: next step to delete from links
  • nextBranchName: name of the next branch
  • nextBranch: next branch instance
  • branchReady: boolean if the branch's dependencies are all complete
  • branchQueue: queue of branches to fork
  • keyStep: join step when iterating though a step's success dictionary keys
  • forkBranch: branch to fork
  • nextStep: step instance associated with a step's nextFail step
  • next: name of the step after nextStep

Functionality

The exitCode is initialized to 0, and getStep retrieves the current step instance by accessing the branch's curStep in the list of the branch's steps. The step's cursorFail list is emptied, and the exitCode is set equal to the return value of calling runStep on the current task, step, and branch.

After running the step, if the exitCode is not -1, the step executed successfully.

  • If the branch's current step has the same value as the branch's lastStep, then the current branch has finished and branch.done is marked True.
    • If the step's success dictionary only has one value, then the next step is either a merge or an exit, and if the next step is "exit", then getStep returns the exitCode. If the step is not caught by the "exit" if clause, the next step is a merge. The nextBranchName is retrieved through the step's success dictionary, and the nextBranch object is retrieved from the task branchesDict. If the branch.traceBranch boolean is marked true, then the nextBranch.traceBranch field is marked True a well, and the current step and the next step are appended to the task.links dictionary. GetStep then checks if the join branch is ready to be executed. Initializing a branchReady boolean as True, getStep iterates through each branch in the nextBranch dependencies. If any branch in the dependencies list is not marked as done, then the branchReady boolean is set to False. After iterating through the dependencies, if branchReady is True, then getStep is called on the nextBranch, and exitCode is set equal to the result of the call.
    • Otherwise, if the success dictionary has multiple values, the next step forks. The branchQueue is initialized. GetStep iterates through each of the keys in the step's success dictionary (where the keys are the join steps, and the values are the steps to be forked). Using the join step as a key to access the value list of steps to be forked, getStep then iterates through each forkBranch to be run in the success dictionary. If branch.traceBranch is True, then each of the forkBranch traceBranch fields are set to be True, the forkBranch is enqueued in the branchQueue, and the step and next step are added to the task.links dictionary. Then, forkBranches is called on the branchQueue, and the exitCode is set to the return value.
  • Otherwise, if the current step is not the same value as the branch's last step, the branch curStep is updated to the step's success step.
    • If the branch's traceBranch boolean is True:
      • If the current step is the same as the branch's lastFail, then the branch's nextFail loop has reconnected with the original branch, and there is a loop in the links dictionary. GetStep loops backwards through task.links, removing key-value entries until the next step to delete does not equal the branch's lastFail step.
    • Else, an entry is added to the task.links map, with the step that just ran as the value, and the next step to run as the key.
    • The exitCode is set equal to calling getStep on the task and the updated branch.

Otherwise, if the exitCode is -1, the step failed.

  • If the current step is already in the branch's failedSteps list (indicating the step has failed before) or the nextFail step is "exit", getStep performs a traceback to find the first step before the current failed step that has failed. A traceback function is called, which takes the current step name, and traces through the task.links dictionary finding the step that called the current step, until it can't find the step in the links keyset, in which that step is returned. That step is appended to the task's restart dictionary. Then the exitCode is returned.
  • Otherwise (if the step has not failed before and the nextFail step is not "exit"), then getStep calls the nextFail step. The nextStep instance is created using the step.nextFail. The current branch is modified, setting traceBranch to True, appending the current step to the failedSteps list, updating the lastFail step to the current step, and moving the curStep to reference the nextFail step (nextStep instance which was created). The current step and the nextFail step pair are appended to the task.links dictionary. GetStep then continuously gets the next step until it is "exit" or the step is already in the branch's steps list or the step is the same as the last step in the branch. For each step it accesses, it pulls the cursor from the previous step if the inherit field for the cursor is marked as True, and the step is added to the branch's steps and the task's steps. When the while loop is broken, if the nextStep is "exit", then the lastStep in the branch is changed to "exit" as well. When the branch is done being modified, getStep is called on the modified branch and the exitCode is set to the return value.

Except Statement

If an error arises, the except block writes to the log file, recording the time, current step, next step, step description, the exit code, and the error message.

The exitCode is set equal to -1, indicating a failure.

Return Value

Returns the exitCode.