1 | |
2 |
|
3 | export type DynSelect_run_id = string |
4 |
|
5 | |
6 | export async function run_id(auth: RT.Databricks) { |
7 | const base = auth.workspace_url.replace(/\/$/, "") |
8 | const response = await fetch(`${base}/api/2.2/jobs/runs/list?limit=25`, { |
9 | headers: { |
10 | Authorization: `Bearer ${auth.token}`, |
11 | Accept: "application/json", |
12 | }, |
13 | }) |
14 | if (!response.ok) { |
15 | throw new Error(`${response.status} ${await response.text()}`) |
16 | } |
17 | const { runs } = (await response.json()) as { |
18 | runs?: { |
19 | run_id: number |
20 | run_name?: string |
21 | state?: { life_cycle_state?: string } |
22 | }[] |
23 | } |
24 | return (runs ?? []).map((r) => ({ |
25 | value: String(r.run_id), |
26 | label: `${r.run_name ?? "run"} (${r.run_id}) — ${r.state?.life_cycle_state ?? "?"}`, |
27 | })) |
28 | } |
29 |
|
30 | |
31 | * Get Job Run |
32 | * Retrieve a single run's metadata, state and task results by run id. |
33 | */ |
34 | export async function main( |
35 | auth: RT.Databricks, |
36 | run_id: DynSelect_run_id, |
37 | include_history: boolean | undefined |
38 | ) { |
39 | const base = auth.workspace_url.replace(/\/$/, "") |
40 | const url = new URL(`${base}/api/2.2/jobs/runs/get`) |
41 | url.searchParams.append("run_id", run_id) |
42 | if (include_history !== undefined) |
43 | url.searchParams.append("include_history", String(include_history)) |
44 |
|
45 | const response = await fetch(url, { |
46 | method: "GET", |
47 | headers: { |
48 | Authorization: `Bearer ${auth.token}`, |
49 | Accept: "application/json", |
50 | }, |
51 | }) |
52 |
|
53 | if (!response.ok) { |
54 | throw new Error(`${response.status} ${await response.text()}`) |
55 | } |
56 |
|
57 | return await response.json() |
58 | } |
59 |
|