From 6d5e954a93b5f2e907e0ce5fdd982c3e64e592f4 Mon Sep 17 00:00:00 2001 From: Nadeesha Cabral Date: Sun, 1 Dec 2024 07:31:27 +1100 Subject: [PATCH] fix: Improve job polling by the client (#164) * fix: Remove max failures based polling termination * fix: Allow partial call failures with allSettled --- sdk-node/src/service.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sdk-node/src/service.ts b/sdk-node/src/service.ts index 89a2b135..274bb5f1 100644 --- a/sdk-node/src/service.ts +++ b/sdk-node/src/service.ts @@ -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"); @@ -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, }); } @@ -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 {