get completed job result if job is completed

Script windmill Verified

by admin ยท 8/13/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * get completed job result if job is completed
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  id: string,
8
  get_started: string | undefined
9
) {
10
  const url = new URL(
11
    `${BASE_URL}/api/w/${workspace}/jobs_u/completed/get_result_maybe/${id}`
12
  );
13
  for (const [k, v] of [["get_started", get_started]]) {
14
    if (v !== undefined && v !== "") {
15
      url.searchParams.append(k, v);
16
    }
17
  }
18
  const response = await fetch(url, {
19
    method: "GET",
20
    headers: {
21
      Authorization: "Bearer " + WM_TOKEN,
22
    },
23
    body: undefined,
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.json();
30
}
31