Skip to content

Commit

Permalink
fix: Improve job polling by the client (#164)
Browse files Browse the repository at this point in the history
* fix: Remove max failures based polling termination

* fix: Allow partial call failures with allSettled
  • Loading branch information
nadeesha authored Nov 30, 2024
1 parent f19f975 commit 6d5e954
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions sdk-node/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { executeFn, Result } from "./execute-fn";
import { FunctionRegistration } from "./types";
import { extractBlobs, validateFunctionArgs } from "./util";

const MAX_CONSECUTIVE_POLL_FAILURES = 50;
const DEFAULT_RETRY_AFTER_SECONDS = 10;

export const log = debug("inferable:client:polling-agent");
Expand Down Expand Up @@ -72,25 +71,21 @@ export class Service {
private async runLoop() {
this.polling = true;

let failureCount = 0;
while (this.polling && failureCount < MAX_CONSECUTIVE_POLL_FAILURES) {
while (this.polling) {
try {
await this.pollIteration();
failureCount = 0;
} catch (e) {
log("Failed poll iteration", e);
failureCount++;
}

await new Promise((resolve) =>
setTimeout(resolve, this.retryAfter * 1000),
);
}

this.polling = false;
//@eslint-disable-next-line no-console
console.error("Quitting polling service", {
service: this.name,
failureCount,
});
}

Expand Down Expand Up @@ -130,11 +125,17 @@ export class Service {
});
}

await Promise.all(
const results = await Promise.allSettled(
pollResult.body.map(async (job) => {
await this.processCall(job);
}),
);

if (results.length > 0) {
log("Completed poll iteration", {
results: results.map((r) => r.status),
});
}
}

private async processCall(call: CallMessage): Promise<void> {
Expand Down

0 comments on commit 6d5e954

Please sign in to comment.