Skip to content

Commit

Permalink
algorithms start sequentially to avoid startup 'storm'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bossett committed Dec 31, 2024
1 parent 2482308 commit e991bd7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
constructor(db: Database, subscriptionEndpoint: string) {
super(db, subscriptionEndpoint)

this._constructor(db, subscriptionEndpoint)
}

async _constructor(db: Database, subscriptionEndpoint: string) {
this.algoManagers = []

const agent = new BskyAgent({ service: 'https://public.api.bsky.app' })
Expand All @@ -35,14 +39,15 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
this.algoManagers.push(new algos[algo].manager(db, agent))
})

const startPromises = this.algoManagers.map(async (algo) => {
if (await algo._start()) {
console.log(`${algo.name}: Started`)
const startAlgosSequentially = async () => {
for (const algo of this.algoManagers) {
if (await algo._start()) {
console.log(`${algo.name}: Started`)
}
}
})
}

/*await */ Promise.all(startPromises)
//})
startAlgosSequentially()
}

public authorList: string[]
Expand Down

0 comments on commit e991bd7

Please sign in to comment.