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.
Cet exercice fait partie du cours
Databricks with the Python SDK
Instructions
- 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.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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 Notbeook
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.____)