0

List Job Runs

by
Published 4 days ago

List recent job runs, optionally filtered to a single job or to active/completed only. Paginate with page_token.

Script databricks Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * List Job Runs
5
 * List recent job runs, optionally filtered to a single job or to active/completed only. Paginate with page_token.
6
 */
7
export async function main(
8
  auth: RT.Databricks,
9
  job_id: number | undefined,
10
  active_only: boolean | undefined,
11
  completed_only: boolean | undefined,
12
  limit: number | undefined,
13
  page_token: string | undefined
14
) {
15
  const base = auth.workspace_url.replace(/\/$/, "")
16
  const url = new URL(`${base}/api/2.2/jobs/runs/list`)
17
  if (job_id !== undefined) url.searchParams.append("job_id", String(job_id))
18
  if (active_only !== undefined)
19
    url.searchParams.append("active_only", String(active_only))
20
  if (completed_only !== undefined)
21
    url.searchParams.append("completed_only", String(completed_only))
22
  if (limit !== undefined) url.searchParams.append("limit", String(limit))
23
  if (page_token !== undefined && page_token !== "")
24
    url.searchParams.append("page_token", page_token)
25

26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: `Bearer ${auth.token}`,
30
      Accept: "application/json",
31
    },
32
  })
33

34
  if (!response.ok) {
35
    throw new Error(`${response.status} ${await response.text()}`)
36
  }
37

38
  return await response.json()
39
}
40