Edits history of script submission #23599 for ' Run Script by Path (windmill)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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_path = string
    
    export async function path() {
      const paths = await wmill.ScriptService.listScriptPaths({
        workspace: wmill.getWorkspace(),
      })
      return paths.map((p) => ({ value: p, label: p }))
    }
    
    /**
     * Run Script by Path
     * Queue a script run and return its job id without waiting for it to finish.
     */
    export async function main(
      path: DynSelect_path,
      args: { [key: string]: any } | undefined,
      scheduled_in_secs: number | undefined,
      tag: string | undefined
    ) {
      return await wmill.JobService.runScriptByPath({
        workspace: wmill.getWorkspace(),
        path,
        requestBody: args ?? {},
        scheduledInSecs: scheduled_in_secs ?? undefined,
        tag: tag || undefined,
      })
    }
    

    Submitted by hugo989 5 hours ago