async function main()

in src/unified-scaler.js [27:73]


async function main() {
  const DEFAULT_CONFIG_LOCATION =
    '/etc/autoscaler-config/autoscaler-config.yaml';

  logger.info(
    `Autoscaler unified Poller/Scaler v${packageVersion} job started`,
  );

  // This is not a long-running process, but we only want to flush the counters
  // when it has completed. So disable flushing here, and enable and flush in
  // the finally {} block
  CountersBase.setTryFlushEnabled(false);

  let configLocation = DEFAULT_CONFIG_LOCATION;

  /*
   * If set, the AUTOSCALER_CONFIG environment variable is used to
   * retrieve the configuration for this instance of the Poller.
   * Please refer to the documentation in the README.md for GKE
   * deployment for more details.
   */

  if (process.env.AUTOSCALER_CONFIG) {
    configLocation = process.env.AUTOSCALER_CONFIG;
    logger.debug(`Using custom config location ${configLocation}`);
  } else {
    logger.debug(`Using default config location ${configLocation}`);
  }

  try {
    const config = await fs.readFile(configLocation, {encoding: 'utf8'});
    const clusters = await pollerCore.checkMemorystoreClusterScaleMetricsLocal(
      JSON.stringify(yaml.load(config)),
    );
    for (const cluster of clusters) {
      await scalerCore.scaleMemorystoreClusterLocal(cluster);
    }
  } catch (err) {
    logger.error({
      message: 'Error in unified poller/scaler wrapper: ${err}',
      err: err,
    });
  } finally {
    CountersBase.setTryFlushEnabled(true);
    await CountersBase.tryFlush();
  }
}