//native
import * as wmill from "windmill-client"
// windmill-client errors only carry the status text: throw the response body, which says why
wmill.OpenAPI.interceptors.response.use(async (response) => {
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return response
})
export type DynSelect_script_path = string
export async function script_path(is_flow: boolean | undefined) {
const ws = wmill.getWorkspace()
const paths = is_flow
? await wmill.FlowService.listFlowPaths({ workspace: ws })
: await wmill.ScriptService.listScriptPaths({ workspace: ws })
return paths.map((p) => ({ value: p, label: p }))
}
/**
* Create Schedule
* Create a schedule that runs a script or flow on a cron expression (6 fields, seconds first, e.g. `0 0 12 * * *`).
*/
export async function main(
path: string,
is_flow: boolean,
script_path: DynSelect_script_path,
cron: string,
timezone: string = "UTC",
args: { [key: string]: any } | undefined,
enabled: boolean = true,
summary: string | undefined
) {
return await wmill.ScheduleService.createSchedule({
workspace: wmill.getWorkspace(),
requestBody: {
path,
schedule: cron,
timezone: timezone || "UTC",
script_path,
is_flow: is_flow ?? false,
args: args ?? {},
enabled: enabled ?? true,
summary: summary || undefined,
},
})
}
Submitted by hugo989 5 hours ago