Skip to content

Commit

Permalink
Dedup processJobs
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Sep 4, 2023
1 parent 32675db commit 86ad9c7
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,38 +185,22 @@ if (import.meta.main) {

const didSubmit = await submitter.handlePublishedBeacon(beacon);

const processJobs = (rounds: number[]): void => {
if (!rounds.length) return;
const past = rounds.filter((r) => r <= n);
const future = rounds.filter((r) => r > n);
console.log(
`Past: %o, Future: %o`,
past,
future,
);
submitter.submitPastRounds(past);
};

// Check jobs every 1.5s, shifted 1200ms from the drand receiving
const shift = 1200;
setTimeout(() =>
jobs.check().then(
(rounds) => {
if (!rounds.length) return;
const past = rounds.filter((r) => r <= n);
const future = rounds.filter((r) => r > n);
console.log(
`Past: %o, Future: %o`,
past,
future,
);
submitter.submitPastRounds(past);
},
(err) => console.error(err),
), shift);
setTimeout(() =>
jobs.check().then(
(rounds) => {
if (!rounds.length) return;
const past = rounds.filter((r) => r <= n);
const future = rounds.filter((r) => r > n);
console.log(
`Past: %o, Future: %o`,
past,
future,
);
submitter.submitPastRounds(past);
},
(err) => console.error(err),
), shift + 1500);
setTimeout(() => jobs.check().then(processJobs, (err) => console.error(err)), shift);
setTimeout(() => jobs.check().then(processJobs, (err) => console.error(err)), shift + 1500);

if (didSubmit) {
// Some seconds after the submission when things are idle, check and log
Expand Down

0 comments on commit 86ad9c7

Please sign in to comment.