0

Enable or Disable Schedule

by
Published Aug 19, 2022

Turn a schedule on or off without changing anything else.

Script windmill Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
import * as wmill from "windmill-client"
4

5
// windmill-client errors only carry the status text: throw the response body, which says why
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
 * Enable or Disable Schedule
28
 * Turn a schedule on or off without changing anything else.
29
 */
30
export async function main(path: DynSelect_path, enabled: boolean) {
31
  return await wmill.ScheduleService.setScheduleEnabled({
32
    workspace: wmill.getWorkspace(),
33
    path,
34
    requestBody: { enabled: enabled ?? false },
35
  })
36
}
37

Other submissions
  • Submitted by admin Deno
    Created 526 days ago
    1
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    export async function main(schedule_path: string, enabled: boolean) {
    4
      const conf = wmill.createConf();
    5
      const schedule_api = new wmill.ScheduleApi(conf);
    6
      return await schedule_api.setScheduleEnabled(
    7
        conf.workspace_id,
    8
        schedule_path,
    9
        {
    10
          enabled,
    11
        }
    12
      );
    13
    }
    14