//native
export type DynSelect_job_id = string
// Dropdown of the workspace's jobs so users pick a job by name instead of typing its numeric id.
export async function job_id(auth: RT.Databricks) {
const base = auth.workspace_url.replace(/\/$/, "")
const response = await fetch(`${base}/api/2.2/jobs/list?limit=100`, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { jobs } = (await response.json()) as {
jobs?: { job_id: number; settings?: { name?: string } }[]
}
return (jobs ?? []).map((j) => ({
value: String(j.job_id),
label: `${j.settings?.name ?? "job"} (${j.job_id})`,
}))
}
/**
* Get Job
* Retrieve a single job's full definition (settings, tasks, schedule) by id.
*/
export async function main(auth: RT.Databricks, job_id: DynSelect_job_id) {
const base = auth.workspace_url.replace(/\/$/, "")
const url = new URL(`${base}/api/2.2/jobs/get`)
url.searchParams.append("job_id", job_id)
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