0
list all completed jobs
One script reply has been approved by the moderators Verified
Created by admin 322 days ago Viewed 9207 times
0
Submitted by admin Typescript (fetch-only)
Verified 322 days ago
1
/**
2
 * list all completed jobs
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  order_desc: string | undefined,
8
  created_by: string | undefined,
9
  parent_job: string | undefined,
10
  script_path_exact: string | undefined,
11
  script_path_start: string | undefined,
12
  schedule_path: string | undefined,
13
  script_hash: string | undefined,
14
  started_before: string | undefined,
15
  started_after: string | undefined,
16
  success: string | undefined,
17
  job_kinds: string | undefined,
18
  args: string | undefined,
19
  result: string | undefined,
20
  tag: string | undefined,
21
  is_skipped: string | undefined,
22
  is_flow_step: string | undefined,
23
  has_null_parent: string | undefined
24
) {
25
  const url = new URL(`${BASE_URL}/api/w/${workspace}/jobs/completed/list`);
26
  for (const [k, v] of [
27
    ["order_desc", order_desc],
28
    ["created_by", created_by],
29
    ["parent_job", parent_job],
30
    ["script_path_exact", script_path_exact],
31
    ["script_path_start", script_path_start],
32
    ["schedule_path", schedule_path],
33
    ["script_hash", script_hash],
34
    ["started_before", started_before],
35
    ["started_after", started_after],
36
    ["success", success],
37
    ["job_kinds", job_kinds],
38
    ["args", args],
39
    ["result", result],
40
    ["tag", tag],
41
    ["is_skipped", is_skipped],
42
    ["is_flow_step", is_flow_step],
43
    ["has_null_parent", has_null_parent],
44
  ]) {
45
    if (v !== undefined && v !== "") {
46
      url.searchParams.append(k, v);
47
    }
48
  }
49
  const response = await fetch(url, {
50
    method: "GET",
51
    headers: {
52
      Authorization: "Bearer " + WM_TOKEN,
53
    },
54
    body: undefined,
55
  });
56
  if (!response.ok) {
57
    const text = await response.text();
58
    throw new Error(`${response.status} ${text}`);
59
  }
60
  return await response.json();
61
}
62