( runId: string | undefined, options?: RunDetailOptions )
| 17 | export type UseRunDetailsResult = UseQueryResult<GetRun>; |
| 18 | |
| 19 | export function useRunDetails( |
| 20 | runId: string | undefined, |
| 21 | options?: RunDetailOptions |
| 22 | ): UseRunDetailsResult { |
| 23 | const { apiUrl, publicApiKey, queryClient } = useTriggerProvider(); |
| 24 | |
| 25 | const { refreshIntervalMs: refreshInterval, ...otherOptions } = options || {}; |
| 26 | |
| 27 | const url = urlWithSearchParams(`${apiUrl}/api/v2/runs/${runId}`, otherOptions); |
| 28 | |
| 29 | return useQuery( |
| 30 | { |
| 31 | queryKey: [`triggerdotdev-run-${runId}`], |
| 32 | queryFn: async () => { |
| 33 | return await zodfetch(GetRunSchema, url, { |
| 34 | method: "GET", |
| 35 | headers: { |
| 36 | Authorization: `Bearer ${publicApiKey}`, |
| 37 | }, |
| 38 | }); |
| 39 | }, |
| 40 | enabled: !!runId, |
| 41 | refetchInterval: (data) => { |
| 42 | if (data?.status && runResolvedStatuses.includes(data.status)) { |
| 43 | return false; |
| 44 | } |
| 45 | if (refreshInterval !== undefined) { |
| 46 | return Math.max(refreshInterval, 500); |
| 47 | } |
| 48 | |
| 49 | return defaultRefreshInterval; |
| 50 | }, |
| 51 | }, |
| 52 | queryClient |
| 53 | ); |
| 54 | } |
no test coverage detected
searching dependent graphs…