Skip to content

Commit

Permalink
added basic limit on number of running events
Browse files Browse the repository at this point in the history
  • Loading branch information
Bossett committed Sep 4, 2024
1 parent b797795 commit 2c5a539
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
public authorList: string[]
public intervalId: NodeJS.Timer

private runningEvents = 0

async handleEvent(evt: RepoEvent) {
if (!isCommit(evt)) return

Expand All @@ -64,6 +66,14 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {

if (!ops) return

const delay = (ms: number) => new Promise((res) => setTimeout(res, ms))

while (this.runningEvents > 128) {
await delay(1000)
}

this.runningEvents++

const postsToDelete = ops.posts.deletes.map((del) => del.uri)

// Transform posts in parallel
Expand Down Expand Up @@ -124,5 +134,7 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
await this.db.replaceOneURI('post', to_insert.uri, to_insert)
})
}

this.runningEvents--
}
}

0 comments on commit 2c5a539

Please sign in to comment.