1 | |
2 | * restart a completed flow at a given step |
3 | * |
4 | */ |
5 | export async function main( |
6 | workspace: string, |
7 | id: string, |
8 | step_id: string, |
9 | branch_or_iteration_n: string, |
10 | scheduled_for: string | undefined, |
11 | scheduled_in_secs: string | undefined, |
12 | parent_job: string | undefined, |
13 | tag: string | undefined, |
14 | job_id: string | undefined, |
15 | include_header: string | undefined, |
16 | invisible_to_owner: string | undefined, |
17 | body: { [k: string]: unknown } |
18 | ) { |
19 | const url = new URL( |
20 | `${BASE_URL}/api/w/${workspace}/jobs/restart/f/${id}/from/${step_id}/${branch_or_iteration_n}` |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["scheduled_for", scheduled_for], |
24 | ["scheduled_in_secs", scheduled_in_secs], |
25 | ["parent_job", parent_job], |
26 | ["tag", tag], |
27 | ["job_id", job_id], |
28 | ["include_header", include_header], |
29 | ["invisible_to_owner", invisible_to_owner], |
30 | ]) { |
31 | if (v !== undefined && v !== "") { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "POST", |
37 | headers: { |
38 | "Content-Type": "application/json", |
39 | Authorization: "Bearer " + WM_TOKEN, |
40 | }, |
41 | body: JSON.stringify(body), |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.text(); |
48 | } |
49 |
|