Edits history of script submission #22656 for ' List Job Runs (databricks)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Job Runs
     * List recent job runs, optionally filtered to a single job or to active/completed only. Paginate with page_token.
     */
    export async function main(
      auth: RT.Databricks,
      job_id: number | undefined,
      active_only: boolean | undefined,
      completed_only: boolean | undefined,
      limit: number | undefined,
      page_token: string | undefined
    ) {
      const base = auth.workspace_url.replace(/\/$/, "")
      const url = new URL(`${base}/api/2.2/jobs/runs/list`)
      if (job_id !== undefined) url.searchParams.append("job_id", String(job_id))
      if (active_only !== undefined)
        url.searchParams.append("active_only", String(active_only))
      if (completed_only !== undefined)
        url.searchParams.append("completed_only", String(completed_only))
      if (limit !== undefined) url.searchParams.append("limit", String(limit))
      if (page_token !== undefined && page_token !== "")
        url.searchParams.append("page_token", page_token)
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 days ago