Skip to content

Commit

Permalink
Log rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Aug 10, 2023
1 parent 67bb52a commit 75df5be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 6 additions & 2 deletions jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ export class JobsObserver {
this.gateway = gatewayAddress;
}

public async check(): Promise<void> {
/**
* Checks gateway for pending jobs and returns the rounds of those jobs as a list
*/
public async check(): Promise<number[]> {
const query = { jobs_desc: { offset: null, limit: 3 } };
const { jobs }: JobsResponse = await this.noisClient.queryContractSmart(this.gateway, query);
if (jobs.length === 0) return; // Nothing to do for us
if (jobs.length === 0) return []; // Nothing to do for us

const rounds = jobs.map(parseRound);
const roundInfos = rounds.map((round) => {
const due = timeOfRound(round) - Date.now();
return `#${round} (due ${formatDuration(due)})`;
});
console.log(`Jobs pending for rounds: %c${roundInfos.join(", ")}`, "color: orange");
return rounds;
}
}
18 changes: 16 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,26 @@ if (import.meta.main) {
const shift = 1200;
setTimeout(() =>
jobs?.check().then(
(_) => {},
(rs) => {
if (!rs.length) return;
console.log(
`Past: %o, Future: %o`,
rs.filter((r) => r <= n),
rs.filter((r) => r > n),
);
},
(err) => console.error(err),
), shift);
setTimeout(() =>
jobs?.check().then(
(_) => {},
(rs) => {
if (!rs.length) return;
console.log(
`Past: %o, Future: %o`,
rs.filter((r) => r <= n),
rs.filter((r) => r > n),
);
},
(err) => console.error(err),
), shift + 1500);

Expand Down

0 comments on commit 75df5be

Please sign in to comment.