0
run script by path
One script reply has been approved by the moderators Verified
Created by admin 424 days ago Viewed 9481 times
0
Submitted by admin Typescript (fetch-only)
Verified 424 days ago
1
/**
2
 * run script by path
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
  body: { [k: string]: unknown }
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
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + WM_TOKEN,
34
    },
35
    body: JSON.stringify(body),
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