async tick()

in components/base-workflow/packages/workflow-engine/lib/workflow-loop.js [80:117]


  async tick() {
    this.stepLoop = undefined;
    return this.catchAndReport(async () => {
      const { stateLabel, stepLoopProvider } = this;

      switch (stateLabel) {
        case 'start':
          await this.fireEvent('workflowStarted');
          this.stepLoop = await stepLoopProvider.getStepLoop();
          if (_.isEmpty(this.stepLoop)) {
            // this means that we have a workflow without any steps information
            await this.fireEvent('workflowIsEmpty');
            return this.passDecision();
          }
          break;
        case 'wait':
        case 'pause':
          this.stepLoop = await stepLoopProvider.getStepLoop();
          break;
        case 'loop':
          this.stepLoop = await stepLoopProvider.getStepLoop();
          break;
        case 'pass':
          throw new Error('Trying to run a workflow loop that has already passed.');
        case 'fail':
          throw new Error('Trying to run a workflow loop that has already failed.');
        default:
          throw new Error(`The workflowLoop has an unsupported "${stateLabel}" state label.`);
      }

      if (_.isUndefined(this.stepLoop)) throw new Error('No step loop is found.');

      const decision = await this.stepLoop.tick();
      if (_.isEmpty(decision) || !_.isObject(decision))
        throw new Error(`The current step ${this.stepLoop.logPrefixStr} didn't return a decision object.`);
      return this.processStepLoopDecision(decision, this.stepLoop);
    });
  }