`io.backgroundPoll()` will fetch data from a URL on an interval. The actual `fetch` requests are performed on the Trigger.dev server, so you don't have to worry about serverless function timeouts. * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://t
(
cacheKey: string | any[],
params: FetchPollOperation
)
| 631 | * ``` |
| 632 | */ |
| 633 | async backgroundPoll<TResponseData>( |
| 634 | cacheKey: string | any[], |
| 635 | params: FetchPollOperation |
| 636 | ): Promise<TResponseData> { |
| 637 | const urlObject = new URL(params.url); |
| 638 | |
| 639 | return (await this.runTask( |
| 640 | cacheKey, |
| 641 | async (task) => { |
| 642 | return task.output; |
| 643 | }, |
| 644 | { |
| 645 | name: `poll ${urlObject.hostname}${urlObject.pathname}`, |
| 646 | params, |
| 647 | operation: "fetch-poll", |
| 648 | icon: "clock-bolt", |
| 649 | noop: false, |
| 650 | properties: [ |
| 651 | { |
| 652 | label: "url", |
| 653 | text: params.url, |
| 654 | }, |
| 655 | { |
| 656 | label: "interval", |
| 657 | text: `${params.interval}s`, |
| 658 | }, |
| 659 | { |
| 660 | label: "timeout", |
| 661 | text: `${params.timeout}s`, |
| 662 | }, |
| 663 | ], |
| 664 | retry: { |
| 665 | limit: 0, |
| 666 | }, |
| 667 | } |
| 668 | )) as TResponseData; |
| 669 | } |
| 670 | |
| 671 | /** `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. |
| 672 | * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information. |