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_path = string |
14 |
|
15 | export async function path() { |
16 | const schedules = await wmill.ScheduleService.listSchedules({ |
17 | workspace: wmill.getWorkspace(), |
18 | perPage: 1000, |
19 | }) |
20 | return schedules.map((s) => ({ |
21 | value: s.path, |
22 | label: `${s.path} (${s.schedule})`, |
23 | })) |
24 | } |
25 |
|
26 | |
27 | * Update Schedule |
28 | * Change a schedule's cron expression, timezone, args or summary. Fields left empty keep their current value; use Enable or Disable Schedule to toggle it. |
29 | */ |
30 | export async function main( |
31 | path: DynSelect_path, |
32 | cron: string | undefined, |
33 | timezone: string | undefined, |
34 | args: { [key: string]: any } | undefined, |
35 | summary: string | undefined |
36 | ) { |
37 | const ws = wmill.getWorkspace() |
38 | |
39 | const current = await wmill.ScheduleService.getSchedule({ |
40 | workspace: ws, |
41 | path, |
42 | }) |
43 | return await wmill.ScheduleService.updateSchedule({ |
44 | workspace: ws, |
45 | path, |
46 | requestBody: { |
47 | ...current, |
48 | schedule: cron || current.schedule, |
49 | timezone: timezone || current.timezone, |
50 | args: args ?? current.args ?? {}, |
51 | summary: summary || current.summary, |
52 | }, |
53 | }) |
54 | } |
55 |
|