MCPcopy Create free account
hub / github.com/agentrpc/agentrpc / pollForJobCompletion

Function pollForJobCompletion

sdk-node/src/polling.ts:272–307  ·  view source on GitHub ↗
(
  client: ReturnType<typeof createApiClient>,
  clusterId: string,
  jobId: string,
  initialStatus?: string | null,
  initialResult: string = "",
  initialResultType: string = "rejection",
)

Source from the content-addressed store, hash-verified

270};
271
272export const pollForJobCompletion = async (
273 client: ReturnType<typeof createApiClient>,
274 clusterId: string,
275 jobId: string,
276 initialStatus?: string | null,
277 initialResult: string = "",
278 initialResultType: string = "rejection",
279): Promise<{
280 status: string;
281 result: string;
282 resultType: string;
283}> => {
284 let status: string | null = initialStatus ?? null;
285 let result: string = initialResult;
286 let resultType: string = initialResultType;
287
288 while (!status || !["failure", "done"].includes(status)) {
289 const details = await client.getJob({
290 params: { clusterId, jobId },
291 query: { waitTime: 20 },
292 });
293
294 if (details.status !== 200) {
295 throw new AgentRPCError(`Failed to fetch job details: ${details.status}`);
296 }
297
298 const body = details.body;
299 status = body.status;
300 result = body.result || "";
301 resultType = body.resultType || "rejection";
302
303 await new Promise((resolve) => setTimeout(resolve, 1000));
304 }
305
306 return { status: status as string, result, resultType };
307};
308
309export const createAndPollJob = async (
310 client: ReturnType<typeof createApiClient>,

Callers 1

createAndPollJobFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected