Skip to content

Commit

Permalink
shuffle pool
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Dec 9, 2024
1 parent 3becc51 commit a4d61e2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/server/jobs/runAllAdapters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import bridgeNetworks from "../../data/bridgeNetworkData";
import { sql } from "../../utils/db";
import { runAdapterToCurrentBlock } from "../../utils/adapter";
import { PromisePool } from "@supercharge/promise-pool";

export const runAllAdapters = async () => {
const lastRecordedBlocks = await sql`SELECT jsonb_object_agg(bridge_id::text, subresult) as result
Expand All @@ -17,15 +18,16 @@ export const runAllAdapters = async () => {
console.error("Failed to store last recorded blocks");
console.error(e);
}
const shuffledBridgeNetworks = bridgeNetworks.sort(() => Math.random() - 0.5);

await Promise.all(
bridgeNetworks.map(async (adapter) => {
await PromisePool.withConcurrency(20)
.for(shuffledBridgeNetworks)
.process(async (adapter) => {
try {
await runAdapterToCurrentBlock(adapter, true, "upsert", lastRecordedBlocks[0].result);
} catch (e) {
console.error(`Failed to run adapter ${adapter.bridgeDbName}`);
console.error(e);
}
})
);
});
};

0 comments on commit a4d61e2

Please sign in to comment.