BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Databricks with the Python SDK

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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 HelloWorld notebook.
  • Run the job you just created.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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.____)
Kodu Düzenle ve Çalıştır