// Cancel paused run according to its branches state
  //      If the run has branches, (it can be branch-paused / user-paused / no-workers-in-group) -
  // then it's a 'virtual' pause, and we should cancel the paused branches. Then, the run itself
  // will be canceled as well.
  //      If it doesn't - just cancel it straight away - extract the Run Object, set its context
  // accordingly and put into the queue.
  private void cancelPausedRun(ExecutionState executionStateToCancel) {
    final List<ExecutionState> branches =
        executionStateService.readByExecutionId(executionStateToCancel.getExecutionId());

    // If the parent is paused because one of the branches is paused, OR, it was paused by the user
    // / no-workers-in-group, but has branches that were not finished (and thus, were paused) -
    // The parent itself will return to the queue after all the branches are ended (due to this
    // cancellation), and then it'll be canceled as well.
    if (branches.size()
        > 1) { // more than 1 means that it has paused branches (branches is at least 1 - the
               // parent)
      for (ExecutionState branch : branches) {
        if (!EMPTY_BRANCH.equals(branch.getBranchId())) { // exclude the base execution
          returnCanceledRunToQueue(branch);
          executionStateService.deleteExecutionState(branch.getExecutionId(), branch.getBranchId());
        }
      }
      executionStateToCancel.setStatus(
          ExecutionStatus
              .PENDING_CANCEL); // when the parent will return to queue - should have the correct
                                // status
    } else {
      returnCanceledRunToQueue(executionStateToCancel);
    }
  }