MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / waitForCompletion

Method waitForCompletion

integrations/openai/src/threads.ts:328–374  ·  view source on GitHub ↗

* Waits for a run to complete by polling in the background.

(
    key: IntegrationTaskKey,
    threadId: string,
    runId: string,
    options: OpenAIRequestOptions = {}
  )

Source from the content-addressed store, hash-verified

326 * Waits for a run to complete by polling in the background.
327 */
328 async waitForCompletion(
329 key: IntegrationTaskKey,
330 threadId: string,
331 runId: string,
332 options: OpenAIRequestOptions = {}
333 ): Promise<OpenAI.Beta.Threads.Run> {
334 return this.runTask(
335 key,
336 async (client, task, io) => {
337 const url = createBackgroundFetchUrl(
338 client,
339 `/threads/${threadId}/runs/${runId}`,
340 this.options.defaultQuery,
341 options
342 );
343
344 const headers = this.options.defaultHeaders ?? {};
345
346 headers["OpenAI-Beta"] = "assistants=v1";
347
348 const completedRun = await io.backgroundPoll<OpenAI.Beta.Threads.Run>("poll", {
349 url,
350 requestInit: {
351 headers: createBackgroundFetchHeaders(client, task.idempotencyKey, headers, options),
352 },
353 interval: 10,
354 timeout: 600,
355 responseFilter: {
356 status: [200],
357 body: {
358 status: ["completed", "expired", "cancelled", "failed", "requires_action"],
359 },
360 },
361 });
362
363 return completedRun;
364 },
365 {
366 name: "Wait for Run Completion",
367 properties: [
368 { label: "threadId", text: threadId },
369 { label: "runId", text: runId },
370 ],
371 },
372 handleOpenAIError
373 );
374 }
375
376 /**
377 * Creates a run.

Callers

nothing calls this directly

Calls 3

createBackgroundFetchUrlFunction · 0.90
runTaskMethod · 0.45

Tested by

no test coverage detected