MCPcopy
hub / github.com/triggerdotdev/trigger.dev / backgroundFetchResponse

Method backgroundFetchResponse

packages/trigger-sdk/src/io.ts:682–727  ·  view source on GitHub ↗

`io.backgroundFetchResponse()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you. * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumabi

(
    cacheKey: string | any[],
    url: string,
    requestInit?: FetchRequestInit,
    options?: {
      retry?: FetchRetryOptions;
      timeout?: FetchTimeoutOptions;
    }
  )

Source from the content-addressed store, hash-verified

680 * - Wildcards: 2xx, 3xx, 4xx, 5xx
681 */
682 async backgroundFetchResponse<TResponseData>(
683 cacheKey: string | any[],
684 url: string,
685 requestInit?: FetchRequestInit,
686 options?: {
687 retry?: FetchRetryOptions;
688 timeout?: FetchTimeoutOptions;
689 }
690 ): Promise<BackgroundFetchResponse<TResponseData>> {
691 const urlObject = new URL(url);
692
693 return (await this.runTask(
694 cacheKey,
695 async (task) => {
696 return task.output;
697 },
698 {
699 name: `fetch response ${urlObject.hostname}${urlObject.pathname}`,
700 params: { url, requestInit, retry: options?.retry, timeout: options?.timeout },
701 operation: "fetch-response",
702 icon: "background",
703 noop: false,
704 properties: [
705 {
706 label: "url",
707 text: url,
708 url,
709 },
710 {
711 label: "method",
712 text: requestInit?.method ?? "GET",
713 },
714 {
715 label: "background",
716 text: "true",
717 },
718 ...(options?.timeout
719 ? [{ label: "timeout", text: `${options.timeout.durationInMs}ms` }]
720 : []),
721 ],
722 retry: {
723 limit: 0,
724 },
725 }
726 )) as BackgroundFetchResponse<TResponseData>;
727 }
728
729 /** `io.sendEvent()` allows you to send an event from inside a Job run. The sent event will trigger any Jobs that are listening for that event (based on the name).
730 * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.

Callers

nothing calls this directly

Calls 1

runTaskMethod · 0.95

Tested by

no test coverage detected