1 | |
2 |
|
3 | export type DynSelect_job_id = string |
4 |
|
5 | |
6 | export async function job_id(auth: RT.Databricks) { |
7 | const base = auth.workspace_url.replace(/\/$/, "") |
8 | const response = await fetch(`${base}/api/2.2/jobs/list?limit=100`, { |
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 { jobs } = (await response.json()) as { |
18 | jobs?: { job_id: number; settings?: { name?: string } }[] |
19 | } |
20 | return (jobs ?? []).map((j) => ({ |
21 | value: String(j.job_id), |
22 | label: `${j.settings?.name ?? "job"} (${j.job_id})`, |
23 | })) |
24 | } |
25 |
|
26 | |
27 | * Run Job Now |
28 | * Trigger a one-off run of an existing job. Pass run parameters in params (e.g. {"job_parameters": {...}}, {"notebook_params": {...}}, {"python_params": [...]}). Returns run_id; poll Get Job Run for completion. |
29 | */ |
30 | export async function main( |
31 | auth: RT.Databricks, |
32 | job_id: DynSelect_job_id, |
33 | params: { [key: string]: any } |
34 | ) { |
35 | const base = auth.workspace_url.replace(/\/$/, "") |
36 | const url = new URL(`${base}/api/2.2/jobs/run-now`) |
37 |
|
38 | const response = await fetch(url, { |
39 | method: "POST", |
40 | headers: { |
41 | Authorization: `Bearer ${auth.token}`, |
42 | "Content-Type": "application/json", |
43 | Accept: "application/json", |
44 | }, |
45 | body: JSON.stringify({ job_id: Number(job_id), ...params }), |
46 | }) |
47 |
|
48 | if (!response.ok) { |
49 | throw new Error(`${response.status} ${await response.text()}`) |
50 | } |
51 |
|
52 | return await response.json() |
53 | } |
54 |
|