async function postPubSubMessage()

in src/poller/poller-core/index.js [131:158]


async function postPubSubMessage(cluster, metrics) {
  const topic = pubSub.topic(assertDefined(cluster.scalerPubSubTopic));

  cluster.metrics = metrics;
  const messageBuffer = Buffer.from(JSON.stringify(cluster), 'utf8');

  return topic
    .publishMessage({data: messageBuffer})
    .then(() =>
      logger.info({
        message: `----- Published message to topic: ${cluster.scalerPubSubTopic}`,
        projectId: cluster.projectId,
        regionId: cluster.regionId,
        clusterId: cluster.clusterId,
        payload: cluster,
      }),
    )
    .catch((err) => {
      logger.error({
        message: `An error occurred when publishing the message to \
          ${cluster.scalerPubSubTopic}: ${err}`,
        projectId: cluster.projectId,
        regionId: cluster.regionId,
        clusterId: cluster.clusterId,
        err: err,
      });
    });
}