Skip to content

Commit

Permalink
Use Promise.all in processReplication call (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel authored May 8, 2024
1 parent 89b3512 commit ebc8ccf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions update.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ const processReplication = async () => {
const process = async () => {
// check if there are any files to process and queue them
const planetState = await getPlanetTimestamp();

let lastProcessedState = await getLastProcessedState();

if (!lastProcessedState) lastProcessedState = planetState - 2;
const files = range(lastProcessedState, planetState + 1);
console.log(`Queueing replication files from ${lastProcessedState} to ${planetState} to process.`);

await Promise.all(files.map(async (f) => {
await storePendingReplications(f);
}));

Array(Number(NUM_WORKERS)).fill().forEach(
async () => await processReplication()
);

await Promise.all(
Array(Number(NUM_WORKERS)).fill().map(
async () => await processReplication()
));
};

process();

0 comments on commit ebc8ccf

Please sign in to comment.