# frozen_string_literal: true require "json" # This module handles the execution of jobs/runs using the DBX API. # For more information about the DBX Jobs API, # see: https://learn.microsoft.com/en-us/azure/databricks/workflows/jobs/jobs-2.0-api module DatabricksJobs def jobs_url "#{@base_url}/api/2.0/jobs/" end # create job # POST /api/2.0/jobs/create/ def create_job(job_json) uri = URI("#{jobs_url}create") request = Net::HTTP::Post.new(uri, request_headers) request.body = job_json response = http.request(request) response.body end # list jobs # GET /api/2.0/jobs/list/ def list_jobs uri = URI("#{jobs_url}list") request = Net::HTTP::Get.new(uri, request_headers) response = http.request(request) response.body end # delete job # POST /api/2.0/jobs/delete/ def delete_job(job_id) uri = URI("#{jobs_url}delete") request = Net::HTTP::Post.new(uri, request_headers) request.body = { "job_id" => job_id }.to_json response = http.request(request) response.body end # get information about a single job # GET /api/2.0/jobs/get/ def job_info(job_id) uri = URI("#{jobs_url}get") request = Net::HTTP::Get.new(uri, request_headers) request.body = { "job_id" => job_id }.to_json response = http.request(request) response.body end # run job # POST /api/2.0/jobs/run-now def run_now(job_id) uri = URI("#{jobs_url}run-now") request = Net::HTTP::Post.new(uri, request_headers) request.body = { "job_id" => job_id }.to_json response = http.request(request) response.body end # submit a one-time run without directly creating a job # POST /api/2.0/jobs/runs/submit def submit_job(job_json) uri = URI("#{jobs_url}runs/submit") request = Net::HTTP::Post.new(uri, request_headers) request.body = job_json response = http.request(request) response.body end # list runs # GET /api/2.0/jobs/runs/list def list_runs(active_only: false) uri = URI("#{jobs_url}runs/list") request = Net::HTTP::Get.new(uri, request_headers) request.body = { "active_only" => active_only }.to_json response = http.request(request) response.body end # get run metadata # GET /api/2.0/jobs/runs/get def get_run(run_id) uri = URI("#{jobs_url}runs/get") request = Net::HTTP::Get.new(uri, request_headers) request.body = { "run_id" => run_id }.to_json response = http.request(request) response.body end # export notebook run as HTML # GET /api/2.0/jobs/runs/export def export_run(run_id) uri = URI("#{jobs_url}runs/export") request = Net::HTTP::Get.new(uri, request_headers) request.body = { "run_id" => run_id }.to_json response = http.request(request) response.body end # cancel a single run # POST /api/2.0/jobs/runs/cancel def cancel_run(run_id) uri = URI("#{jobs_url}runs/cancel") request = Net::HTTP::Post.new(uri, request_headers) request.body = { "run_id" => run_id }.to_json response = http.request(request) response.body end # cancel all active runs of a job # POST /api/2.0/jobs/runs/cancel-all def cancel_all_runs(job_id) uri = URI("#{jobs_url}runs/cancel-all") request = Net::HTTP::Post.new(uri, request_headers) request.body = { "job_id" => job_id }.to_json response = http.request(request) response.body end # get run output # GET /api/2.0/jobs/runs/get-output def get_run_output(run_id) uri = URI("#{jobs_url}runs/get-output") request = Net::HTTP::Get.new(uri, request_headers) request.body = { "run_id" => run_id }.to_json response = http.request(request) response.body end # delete inactive run # POST /api/2.0/jobs/runs/delete def delete_run(run_id) uri = URI("#{jobs_url}runs/delete") request = Net::HTTP::Post.new(uri, request_headers) request.body = { "run_id" => run_id }.to_json response = http.request(request) response.body end end