export async function onIndexDeployedHandler()

in firestore-semantic-search/functions/src/functions/on_index_deployed.ts [37:62]


export async function onIndexDeployedHandler(event: any) {
  try {
    const {protoPayload, operation} = event.data;

    functionsv2.logger.info('EVENT RECEIVED', event);

    if (!operation) return;

    // Check if the operation is the last one, which means the index is ready.
    if (operation && !operation.last) return;

    const endpoint = await getDeployedIndex(protoPayload.resourceName);

    // Add the index endpoint to the metadata document.
    await admin
      .firestore()
      .doc(config.metadataDoc)
      .update({
        operation: FieldValue.delete(),
        status: IndexStatus.DEPLOYED,
        publicEndpointDomainName: `${endpoint}`,
      });
  } catch (error) {
    functionsv2.logger.error(error);
  }
}