create an endpoint to fetch all rss feeds

This commit is contained in:
Hongbo Wu
2023-07-07 21:15:42 +08:00
parent 0ad434ada5
commit 68667053c8
4 changed files with 86 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import { google } from '@google-cloud/tasks/build/protos/protos'
import axios from 'axios'
import { nanoid } from 'nanoid'
import { Recommendation } from '../elastic/types'
import { Subscription } from '../entity/subscription'
import { env } from '../env'
import {
ArticleSavingRequestStatus,
@ -559,4 +560,31 @@ export const enqueueThumbnailTask = async (
return createdTasks[0].name
}
export const enqueueRssFeedFetch = async (
rssFeedSubscription: Subscription
): Promise<string> => {
const { GOOGLE_CLOUD_PROJECT } = process.env
const payload = {
subscriptionId: rssFeedSubscription.id,
userId: rssFeedSubscription.user.id,
feedUrl: rssFeedSubscription.url,
}
const createdTasks = await createHttpTaskWithToken({
project: GOOGLE_CLOUD_PROJECT,
queue: 'omnivore-rss-feed-queue',
payload,
taskHandlerUrl: env.queue.rssFeedTaskHandlerUrl,
})
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