1 | |
2 |
|
3 | import * as wmill from "windmill-client" |
4 |
|
5 | |
6 | wmill.OpenAPI.interceptors.response.use(async (response) => { |
7 | if (!response.ok) { |
8 | throw new Error(`${response.status} ${await response.text()}`) |
9 | } |
10 | return response |
11 | }) |
12 |
|
13 | export type DynSelect_script_path = string |
14 |
|
15 | export async function script_path(is_flow: boolean | undefined) { |
16 | const ws = wmill.getWorkspace() |
17 | const paths = is_flow |
18 | ? await wmill.FlowService.listFlowPaths({ workspace: ws }) |
19 | : await wmill.ScriptService.listScriptPaths({ workspace: ws }) |
20 | return paths.map((p) => ({ value: p, label: p })) |
21 | } |
22 |
|
23 | |
24 | * Create Schedule |
25 | * Create a schedule that runs a script or flow on a cron expression (6 fields, seconds first, e.g. `0 0 12 * * *`). |
26 | */ |
27 | export async function main( |
28 | path: string, |
29 | is_flow: boolean, |
30 | script_path: DynSelect_script_path, |
31 | cron: string, |
32 | timezone: string = "UTC", |
33 | args: { [key: string]: any } | undefined, |
34 | enabled: boolean = true, |
35 | summary: string | undefined |
36 | ) { |
37 | return await wmill.ScheduleService.createSchedule({ |
38 | workspace: wmill.getWorkspace(), |
39 | requestBody: { |
40 | path, |
41 | schedule: cron, |
42 | timezone: timezone || "UTC", |
43 | script_path, |
44 | is_flow: is_flow ?? false, |
45 | args: args ?? {}, |
46 | enabled: enabled ?? true, |
47 | summary: summary || undefined, |
48 | }, |
49 | }) |
50 | } |
51 |
|