//native
export type DynSelect_warehouse_id = string
// Dropdown of the workspace's SQL warehouses so users pick by name instead of typing the id.
export async function warehouse_id(auth: RT.Databricks) {
const base = auth.workspace_url.replace(/\/$/, "")
const response = await fetch(`${base}/api/2.0/sql/warehouses`, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { warehouses } = (await response.json()) as {
warehouses?: { id: string; name?: string; state?: string }[]
}
return (warehouses ?? []).map((w) => ({
value: w.id,
label: `${w.name ?? w.id} (${w.state ?? "?"})`,
}))
}
/**
* Stop SQL Warehouse
* Stop a running SQL warehouse. Returns {} on success; the warehouse transitions through STOPPING to STOPPED asynchronously.
*/
export async function main(
auth: RT.Databricks,
warehouse_id: DynSelect_warehouse_id
) {
const base = auth.workspace_url.replace(/\/$/, "")
const url = new URL(`${base}/api/2.0/sql/warehouses/${warehouse_id}/stop`)
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const text = await response.text()
return text ? JSON.parse(text) : { success: true }
}
Submitted by hugo989 5 days ago