0
list all queued jobs
One script reply has been approved by the moderators Verified
Created by admin 648 days ago Viewed 22731 times
0
Submitted by admin Typescript (fetch-only)
Verified 648 days ago
1
/**
2
 * list all queued 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
  scheduled_for_before_now: string | undefined,
18
  job_kinds: string | undefined,
19
  suspended: string | undefined,
20
  running: string | undefined,
21
  args: string | undefined,
22
  result: string | undefined,
23
  tag: string | undefined,
24
  all_workspaces: string | undefined
25
) {
26
  const url = new URL(`${BASE_URL}/api/w/${workspace}/jobs/queue/list`);
27
  for (const [k, v] of [
28
    ["order_desc", order_desc],
29
    ["created_by", created_by],
30
    ["parent_job", parent_job],
31
    ["script_path_exact", script_path_exact],
32
    ["script_path_start", script_path_start],
33
    ["schedule_path", schedule_path],
34
    ["script_hash", script_hash],
35
    ["started_before", started_before],
36
    ["started_after", started_after],
37
    ["success", success],
38
    ["scheduled_for_before_now", scheduled_for_before_now],
39
    ["job_kinds", job_kinds],
40
    ["suspended", suspended],
41
    ["running", running],
42
    ["args", args],
43
    ["result", result],
44
    ["tag", tag],
45
    ["all_workspaces", all_workspaces],
46
  ]) {
47
    if (v !== undefined && v !== "") {
48
      url.searchParams.append(k, v);
49
    }
50
  }
51
  const response = await fetch(url, {
52
    method: "GET",
53
    headers: {
54
      Authorization: "Bearer " + WM_TOKEN,
55
    },
56
    body: undefined,
57
  });
58
  if (!response.ok) {
59
    const text = await response.text();
60
    throw new Error(`${response.status} ${text}`);
61
  }
62
  return await response.json();
63
}
64