async execute()

in common/lib/plugins/efm/host_monitoring_connection_plugin.ts [86:150]


  async execute<T>(methodName: string, methodFunc: () => Promise<T>, methodArgs: any): Promise<T> {
    const isEnabled: boolean = WrapperProperties.FAILURE_DETECTION_ENABLED.get(this.properties);

    if (!isEnabled || !SubscribedMethodHelper.NETWORK_BOUND_METHODS.includes(methodName)) {
      return methodFunc();
    }

    const failureDetectionTimeMillis: number = WrapperProperties.FAILURE_DETECTION_TIME_MS.get(this.properties) as number;
    const failureDetectionIntervalMillis: number = WrapperProperties.FAILURE_DETECTION_INTERVAL_MS.get(this.properties) as number;
    const failureDetectionCount: number = WrapperProperties.FAILURE_DETECTION_COUNT.get(this.properties) as number;

    let result: T;
    let monitorContext: MonitorConnectionContext | null = null;

    try {
      logger.debug(Messages.get("HostMonitoringConnectionPlugin.activatedMonitoring", methodName));
      const monitoringHostInfo: HostInfo = await this.getMonitoringHostInfo();

      monitorContext = await this.monitorService.startMonitoring(
        this.pluginService.getCurrentClient().targetClient,
        monitoringHostInfo.allAliases,
        monitoringHostInfo,
        this.properties,
        failureDetectionTimeMillis,
        failureDetectionIntervalMillis,
        failureDetectionCount
      );

      result = await Promise.race([monitorContext.trackHealthStatus(), methodFunc()])
        .then((result: any) => {
          return result;
        })
        .catch((error: any) => {
          throw error;
        });
    } finally {
      if (monitorContext != null) {
        await this.monitorService.stopMonitoring(monitorContext);
        logger.debug(Messages.get("HostMonitoringConnectionPlugin.monitoringDeactivated", methodName));

        if (monitorContext.isHostUnhealthy) {
          const monitoringHostInfo = await this.getMonitoringHostInfo();
          if (monitoringHostInfo) {
            this.pluginService.setAvailability(monitoringHostInfo.allAliases, HostAvailability.NOT_AVAILABLE);
          }

          const targetClient = this.pluginService.getCurrentClient().targetClient;
          let isClientValid = false;
          if (targetClient) {
            isClientValid = await this.pluginService.isClientValid(targetClient);
          }

          if (!targetClient || !isClientValid) {
            if (targetClient) {
              await this.pluginService.abortTargetClient(targetClient);
            }
            // eslint-disable-next-line no-unsafe-finally
            throw new UnavailableHostError(Messages.get("HostMonitoringConnectionPlugin.unavailableHost", monitoringHostInfo.host));
          }
        }
      }
    }

    return result;
  }