0
run script by path
One script reply has been approved by the moderators Verified
Created by admin 198 days ago Viewed 85 times
0
Submitted by admin Typescript (fetch-only)
Verified 198 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
  job_id: string | undefined,
10
  include_header: string | undefined,
11
  queue_limit: string | undefined,
12
  body: { [k: string]: unknown }
13
) {
14
  const url = new URL(
15
    `${BASE_URL}/api/w/${workspace}/jobs/run_wait_result/p/${path}`
16
  );
17
  for (const [k, v] of [
18
    ["parent_job", parent_job],
19
    ["job_id", job_id],
20
    ["include_header", include_header],
21
    ["queue_limit", queue_limit],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + WM_TOKEN,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41