简体   繁体   English

用于执行 Databricks 作业的笔记本

[英]notebook to execute Databricks job

Is there an api or other way to programmatically run a Databricks job.是否有 api 或其他方式以编程方式运行 Databricks 作业。 Ideally, we would like to call a Databricks job from a notebook.理想情况下,我们希望从笔记本中调用 Databricks 作业。 Following just gives currently running job id but that's not very useful:以下只是给出当前正在运行的作业 ID,但这不是很有用:

dbutils.notebook.entry_point.getDbutils().notebook().getContext().currentRunId().toString()

To run a databricks job, you can use Jobs API .要运行数据块作业,您可以使用Jobs API I have a databricks job called for_repro which I ran using the 2 ways provided below from databricks notebook.我有一个名为for_repro的 databricks 作业,我使用 databricks notebook 下面提供的 2 种方式运行该作业。

Using requests library:使用requests库:

  • You can create an access token by navigating to Settings -> User settings .您可以通过导航到Settings -> User settings创建访问令牌。 Under Access token tab, click generate token.Access token选项卡下,单击生成令牌。
  • Use the above generated token along with the following code.将上面生成的令牌与以下代码一起使用。
import requests
import json

my_json = {"job_id": <your_job-id>}    

auth = {"Authorization": "Bearer <your_access-token>"}

response = requests.post('https://<databricks-instance>/api/2.0/jobs/run-now', json = my_json, headers=auth).json()
print(response)

在此处输入图像描述


  • The <databricks-instance> value from the above code can be extracted from your workspace URL.上述代码中的<databricks-instance>值可以从您的工作区 URL 中提取。

在此处输入图像描述


Using %sh magic command script:使用 %sh 魔法命令脚本:

  • You can also use magic command %sh in your python notebook cell to run a databricks job.您还可以在 python 笔记本单元格中使用魔术命令 %sh 来运行数据块作业。
%sh

curl --netrc --request POST --header "Authorization: Bearer <access_token>" \
https://<databricks-instance>/api/2.0/jobs/run-now \
--data '{"job_id": <your job id>}'

在此处输入图像描述

  • The following is my job details and run history for reference.以下是我的工作详情和运行历史供参考。在此处输入图像描述

Refer to this Microsoft documentation to know all other operations that can be achieved using Jobs API .请参阅此 Microsoft 文档以了解使用Jobs API可以实现的所有其他操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Databricks 笔记本命令仅在计划为作业时跳过 - Databricks notebook command skipped only when scheduled as a job 使用Apache Airflow使用PySpark代码执行Databricks Notebook - Execute a Databricks Notebook with PySpark code using Apache Airflow 在 Databricks 中运行作业时如何获取作业名称。 这不是基于笔记本的工作 - How can I get a job name while the job running in Databricks. It is not notebook based job 使用 Databricks Job api 调用 databricks notebook 使用 AWS Lambda function 运行-提交端点 - Calling databricks notebook using Databricks Job api runs-submit endpoint using AWS Lambda function 您如何使用 Databricks 作业任务参数或笔记本变量来设置彼此的值? - How do you use either Databricks Job Task parameters or Notebook variables to set the value of each other? 与作为作业运行时相比,Databricks 笔记本在手动触发时运行速度更快 - Databricks notebook runs faster when triggered manually compared to when run as a job Databricks笔记本挂用pytorch - Databricks notebook hanging with pytorch DataBricks:笔记本:Python:FileNotFoundError - DataBricks: notebook : Python: FileNotFoundError Azure Databricks Python 作业 - Azure Databricks Python Job 如何将参数发送到数据块笔记本? - how to send parameters to databricks notebook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM