0
create schedule
One script reply has been approved by the moderators Verified
Created by admin 263 days ago Viewed 5481 times
0
Submitted by admin Typescript (fetch-only)
Verified 263 days ago
1
/**
2
 * create schedule
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  body: {
8
    path: string;
9
    schedule: string;
10
    timezone: string;
11
    script_path: string;
12
    is_flow: boolean;
13
    args: { [k: string]: unknown };
14
    enabled?: boolean;
15
    on_failure?: string;
16
    on_failure_times?: number;
17
    on_failure_exact?: boolean;
18
    on_failure_extra_args?: { [k: string]: unknown };
19
    on_recovery?: string;
20
    on_recovery_times?: number;
21
    on_recovery_extra_args?: { [k: string]: unknown };
22
    ws_error_handler_muted?: boolean;
23
    retry?: {
24
      constant?: { attempts?: number; seconds?: number; [k: string]: unknown };
25
      exponential?: {
26
        attempts?: number;
27
        multiplier?: number;
28
        seconds?: number;
29
        random_factor?: number;
30
        [k: string]: unknown;
31
      };
32
      [k: string]: unknown;
33
    };
34
    no_flow_overlap?: boolean;
35
    summary?: string;
36
    tag?: string;
37
    [k: string]: unknown;
38
  }
39
) {
40
  const url = new URL(`${BASE_URL}/api/w/${workspace}/schedules/create`);
41

42
  const response = await fetch(url, {
43
    method: "POST",
44
    headers: {
45
      "Content-Type": "application/json",
46
      Authorization: "Bearer " + WM_TOKEN,
47
    },
48
    body: JSON.stringify(body),
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.text();
55
}
56