Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

untested fix: RSS ingester runs in a hot loop #109

Open
wants to merge 1 commit into
base: translations
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/repco-core/src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
`ingest ${uid}: ${records.length} records, ${entities.length} entities, ${errors.length} errors`,
)

const finished = records.length === 0
const finished = records.length === 0 || nextCursor == cursor
if (errors) {
for (const error of errors) {
log.warn({
Expand Down Expand Up @@ -685,7 +685,7 @@
const nextCursor = records[records.length - 1].uid
if (nextCursor === cursor) break

const { entities, errors } = await persistAndMapSourceRecords(

Check warning on line 688 in packages/repco-core/src/datasource.ts

View workflow job for this annotation

GitHub Actions / build-and-test

'errors' is assigned a value but never used. Allowed unused vars must match /^_/u
repo,
datasource,
records,
Expand Down
19 changes: 13 additions & 6 deletions packages/repco-core/src/datasources/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class RssDataSource extends BaseDataSource implements DataSource {
// This means: Increase page number to keep fetching untilwe reach the most recent pub date.
} else {
nextCursor = {
lastCompletionDate: cursor.lastCompletionDate,
lastCompletionDate: mostRecentPubDate,
pageNumber: page + 1,
mostRecentPubDate,
leastRecentPubDate,
Expand Down Expand Up @@ -264,7 +264,6 @@ export class RssDataSource extends BaseDataSource implements DataSource {
// }

async fetchPage(url: URL): Promise<string> {
// console.log('FETCH', url.toString())
const maxRetries = 50
let timeout = 1
let retries = 0
Expand Down Expand Up @@ -303,14 +302,23 @@ export class RssDataSource extends BaseDataSource implements DataSource {

async fetchUpdates(cursorInput: string | null): Promise<FetchUpdatesResult> {
const cursor = parseCursor(cursorInput)
const nextCursor = cursor
const date = new Date()
const { url, xml } = await this._crawlNewestUntil(cursor.newest)

try {
const feed = await this.parser.parseString(xml)
feed.items = feed.items.filter((item) => item.link != undefined)
cursor.newest = this.extractNextCursor(cursor.newest, feed)
const nextNewestCursor = this.extractNextCursor(cursor.newest, feed)

// If the cursor didn't change, there are no new records on the page, so do early return
if (JSON.stringify(nextNewestCursor) === JSON.stringify(cursor.newest)) {
return { cursor: JSON.stringify(cursor), records: [] }
}

const nextCursor = {
newest: nextNewestCursor,
oldest: cursor.oldest,
}

const sourceUri = new URL(this.endpoint)
sourceUri.hash = date.toISOString()
Expand All @@ -327,9 +335,8 @@ export class RssDataSource extends BaseDataSource implements DataSource {
}
} catch (err) {
log.error(`Failed to parse feed from ${url.toString()}: ${err}`)
if (nextCursor.newest.pageNumber) nextCursor.newest.pageNumber += 1
return {
cursor: JSON.stringify(nextCursor),
cursor: JSON.stringify(cursor),
records: [],
}
}
Expand Down
Loading