Enqueue text to speech tasks

This commit is contained in:
Hongbo Wu
2022-08-12 17:53:41 +08:00
parent 4b42d013ca
commit 94f9dd9e6e
7 changed files with 174 additions and 4 deletions

View File

@ -325,4 +325,35 @@ export const enqueueSyncWithIntegration = async (
return createdTasks[0].name
}
export const enqueueTextToSpeech = async (
userId: string,
pageId: string
): Promise<string> => {
const { GOOGLE_CLOUD_PROJECT } = process.env
const payload = {
userId,
pageId,
}
// If there is no Google Cloud Project Id exposed, it means that we are in local environment
if (env.dev.isLocal || !GOOGLE_CLOUD_PROJECT) {
return nanoid()
}
const createdTasks = await createHttpTaskWithToken({
project: GOOGLE_CLOUD_PROJECT,
payload,
taskHandlerUrl: env.queue.textToSpeechTaskHandlerUrl,
})
if (!createdTasks || !createdTasks[0].name) {
logger.error(`Unable to get the name of the task`, {
payload,
createdTasks,
})
throw new CreateTaskError(`Unable to get the name of the task`)
}
return createdTasks[0].name
}
export default createHttpTaskWithToken