From e991bd7a0e3d51594ba41f6a7c6d704678b6751c Mon Sep 17 00:00:00 2001 From: Bossett Date: Tue, 31 Dec 2024 02:42:55 +0000 Subject: [PATCH] algorithms start sequentially to avoid startup 'storm' --- src/subscription.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/subscription.ts b/src/subscription.ts index a291047..cdd24c9 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -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' }) @@ -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[]