Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve job polling by the client #164

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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