Create and run a Databricks job
In this exercise, you will create a job that runs a notebook with name HelloWorld that simply prints "Hello World". You can run whatever code that you want in the notebook referenced in the job.
This job needs to be explicitly told when to run.
The notebook path is dependent on the username of the authenticated user for the workspace and is structured as follows:
/Users/${username}/${notebook_name}.
We have already created the WorkspaceClient(), storing as w.
Latihan ini adalah bagian dari kursus
Databricks with the Python SDK
Petunjuk latihan
- Retrieve the username of the current user in the workspace to generate the notebook path for notebook with name
HelloWorld. - Create a job that runs the
HelloWorldnotebook. - Run the job you just created.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Retrieve the notebook path of notebook in current user's workspace called 'HelloWorld'
notebook_path = f'/Users/{w.____.me().____}/HelloWorld'
# Create a job that runs the HelloWorld Notebook
created_job = w.jobs.____(name='sdk-dc-project-task',
tasks=[
jobs.____(description="create_notebook_test",
# Set the notebook_path
notebook_task=jobs.NotebookTask(
notebook_path=____),
task_key="my-key")
])
# Run job
w.jobs.____(created_job.____)