async getResultTask()

in common/lib/plugins/failover/reader_failover_handler.ts [202:232]


  async getResultTask(hosts: HostInfo[], numTasks: number, i: number, failoverTaskId: string) {
    const tasks: Promise<ReaderFailoverResult>[] = [];
    const firstTask = new ConnectionAttemptTask(this.initialConnectionProps, this.pluginService, hosts[i], i, this.taskHandler, failoverTaskId);
    tasks.push(firstTask.call());
    let secondTask: ConnectionAttemptTask;
    if (numTasks === 2) {
      secondTask = new ConnectionAttemptTask(this.initialConnectionProps, this.pluginService, hosts[i + 1], i + 1, this.taskHandler, failoverTaskId);
      tasks.push(secondTask.call());
    }

    return await Promise.any(tasks).catch((error: AggregateError) => {
      let errors: string = "";
      for (const e of error.errors) {
        // Propagate errors that are not caused by network errors.
        if (!this.pluginService.isNetworkError(e)) {
          errors += `\n\t${e} - ${e.message}`;
        }
      }
      if (errors) {
        const awsWrapperError = new AwsWrapperError(
          Messages.get(
            "ClusterAwareReaderFailoverHandler.batchFailed",
            `[${hosts[i].hostId}${numTasks === 2 ? `, ${hosts[i + 1].hostId}` : ``}]`,
            `[\n${errors}\n]`
          )
        );
        return new ReaderFailoverResult(null, null, false, awsWrapperError);
      }
      return new ReaderFailoverResult(null, null, false, undefined);
    });
  }