run script by path with get

Script windmill Verified

by admin ยท 8/13/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * run script by path with get
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  path: string,
8
  parent_job: string | undefined,
9
  tag: string | undefined,
10
  job_id: string | undefined,
11
  include_header: string | undefined,
12
  queue_limit: string | undefined,
13
  payload: string | undefined
14
) {
15
  const url = new URL(
16
    `${BASE_URL}/api/w/${workspace}/jobs/run_wait_result/p/${path}`
17
  );
18
  for (const [k, v] of [
19
    ["parent_job", parent_job],
20
    ["tag", tag],
21
    ["job_id", job_id],
22
    ["include_header", include_header],
23
    ["queue_limit", queue_limit],
24
    ["payload", payload],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + WM_TOKEN,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43