Skip to content

Commit 94774a1

Browse files
committed
fix: enhance mqRSSRunParser to handle remote items and enqueue them correctly
1 parent 843dbc0 commit 94774a1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/functions/mq/rss/runParser.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { MQ_QUEUES } from 'podverse-helpers';
12
import { parseRSSFeedAndSaveToDatabase } from "podverse-parser";
23
import { MQQueueName, ActiveMQArtemisService } from "@queue/services/activeMQArtemis";
4+
import { mqRSSAdd } from './add';
35

46
export const mqRSSRunParser = async (
57
activeMQArtemisService: ActiveMQArtemisService,
@@ -14,7 +16,18 @@ export const mqRSSRunParser = async (
1416

1517
const { url, podcast_index_id, options } = receivedMessage;
1618
if (url || podcast_index_id) {
17-
await parseRSSFeedAndSaveToDatabase(url, podcast_index_id, options);
19+
const result = await parseRSSFeedAndSaveToDatabase(url, podcast_index_id, options);
20+
21+
if (result && Array.isArray(result.remoteItemsToParse) && result.remoteItemsToParse.length > 0) {
22+
const mqConfig = MQ_QUEUES['rss-slow'];
23+
for (const item of result.remoteItemsToParse) {
24+
try {
25+
await mqRSSAdd(activeMQArtemisService, { queueName: mqConfig.queueName, dedupeCacheTimeMS: mqConfig.dedupeCacheTimeMS, priority: mqConfig.priority, closeAfterSend: false, feedUrl: item.url, podcast_index_id: item.podcast_index_id }, item.options);
26+
} catch (err) {
27+
console.error('Error enqueueing remote item', err as Error);
28+
}
29+
}
30+
}
1831
context.delivery?.accept();
1932
} else {
2033
throw new Error(`mqRSSRunParser: url or podcast_index_id not found in message ${bodyStr}`);

0 commit comments

Comments
 (0)