async function reindex()

in lambda/recipes-responder/src/commandline-reindex.ts [68:103]


async function reindex(
	queryUri: string,
	staticBucketName: string,
	fastlyApiKey: string,
	contentPrefix: string,
	outgoingEventBus: string,
): Promise<void> {
	const pollingResult = await retrieveContent(queryUri);
	switch (pollingResult.action) {
		case PollingAction.CONTENT_EXISTS:
			console.log(
				`Found article with title '${
					pollingResult.content?.webTitle ?? ''
				}' published ${
					pollingResult.content?.webPublicationDate?.iso8601 ?? ''
				}`,
			);
			if (pollingResult.content) {
				await handleContentUpdate({
					content: pollingResult.content,
					staticBucketName,
					fastlyApiKey,
					contentPrefix,
					outgoingEventBus,
				});
			} else {
				throw new Error(
					'Got a positive result but no content?? This must be a bug :(',
				);
			}
			break;
		default:
			console.error(`Unable to retrieve content from ${queryUri}`);
			await new Promise((resolve) => setTimeout(resolve, 2000));
	}
}