Skip to content

prefect_databricks.jobs

This is a module containing tasks for interacting with: Databricks jobs

jobs_create(databricks_credentials, name='Untitled', tags=None, tasks=None, job_clusters=None, email_notifications=None, webhook_notifications=None, timeout_seconds=None, schedule=None, max_concurrent_runs=None, git_source=None, format=None, access_control_list=None, parameters=None) async

Create a new job.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
name str

An optional name for the job, e.g. A multitask job.

'Untitled'
tags Dict

A map of tags associated with the job. These are forwarded to the cluster as cluster tags for jobs clusters, and are subject to the same limitations as cluster tags. A maximum of 25 tags can be added to the job, e.g.

{"cost-center": "engineering", "team": "jobs"}
None
tasks Optional[List[JobTaskSettings]]

A list of task specifications to be executed by this job, e.g.

[
    {
        "task_key": "Sessionize",
        "description": "Extracts session data from events",
        "depends_on": [],
        "existing_cluster_id": "0923-164208-meows279",
        "spark_jar_task": {
            "main_class_name": "com.databricks.Sessionize",
            "parameters": ["--data", "dbfs:/path/to/data.json"],
        },
        "libraries": [{"jar": "dbfs:/mnt/databricks/Sessionize.jar"}],
        "timeout_seconds": 86400,
        "max_retries": 3,
        "min_retry_interval_millis": 2000,
        "retry_on_timeout": False,
    },
    {
        "task_key": "Orders_Ingest",
        "description": "Ingests order data",
        "depends_on": [],
        "job_cluster_key": "auto_scaling_cluster",
        "spark_jar_task": {
            "main_class_name": "com.databricks.OrdersIngest",
            "parameters": ["--data", "dbfs:/path/to/order-data.json"],
        },
        "libraries": [{"jar": "dbfs:/mnt/databricks/OrderIngest.jar"}],
        "timeout_seconds": 86400,
        "max_retries": 3,
        "min_retry_interval_millis": 2000,
        "retry_on_timeout": False,
    },
    {
        "task_key": "Match",
        "description": "Matches orders with user sessions",
        "depends_on": [
            {"task_key": "Orders_Ingest"},
            {"task_key": "Sessionize"},
        ],
        "new_cluster": {
            "spark_version": "7.3.x-scala2.12",
            "node_type_id": "i3.xlarge",
            "spark_conf": {"spark.speculation": True},
            "aws_attributes": {
                "availability": "SPOT",
                "zone_id": "us-west-2a",
            },
            "autoscale": {"min_workers": 2, "max_workers": 16},
        },
        "notebook_task": {
            "notebook_path": "/Users/user.name@databricks.com/Match",
            "source": "WORKSPACE",
            "base_parameters": {"name": "John Doe", "age": "35"},
        },
        "timeout_seconds": 86400,
        "max_retries": 3,
        "min_retry_interval_millis": 2000,
        "retry_on_timeout": False,
    },
]
None
job_clusters Optional[List[JobCluster]]

A list of job cluster specifications that can be shared and reused by tasks of this job. Libraries cannot be declared in a shared job cluster. You must declare dependent libraries in task settings, e.g.

[
    {
        "job_cluster_key": "auto_scaling_cluster",
        "new_cluster": {
            "spark_version": "7.3.x-scala2.12",
            "node_type_id": "i3.xlarge",
            "spark_conf": {"spark.speculation": True},
            "aws_attributes": {
                "availability": "SPOT",
                "zone_id": "us-west-2a",
            },
            "autoscale": {"min_workers": 2, "max_workers": 16},
        },
    }
]
None
email_notifications JobEmailNotifications

An optional set of email addresses that is notified when runs of this job begin or complete as well as when this job is deleted. The default behavior is to not send any emails. Key-values: - on_start: A list of email addresses to be notified when a run begins. If not specified on job creation, reset, or update, the list is empty, and notifications are not sent, e.g. ["user.name@databricks.com"] - on_success: A list of email addresses to be notified when a run successfully completes. A run is considered to have completed successfully if it ends with a TERMINATED life_cycle_state and a SUCCESSFUL result_state. If not specified on job creation, reset, or update, the list is empty, and notifications are not sent, e.g. ["user.name@databricks.com"] - on_failure: A list of email addresses to notify when a run completes unsuccessfully. A run is considered unsuccessful if it ends with an INTERNAL_ERROR life_cycle_state or a SKIPPED, FAILED, or TIMED_OUT result_state. If not specified on job creation, reset, or update, or the list is empty, then notifications are not sent. Job-level failure notifications are sent only once after the entire job run (including all of its retries) has failed. Notifications are not sent when failed job runs are retried. To receive a failure notification after every failed task (including every failed retry), use task-level notifications instead, e.g. ["user.name@databricks.com"] - no_alert_for_skipped_runs: If true, do not send email to recipients specified in on_failure if the run is skipped.

None
webhook_notifications WebhookNotifications

A collection of system notification IDs to notify when runs of this job begin or complete. The default behavior is to not send any system notifications. Key-values: - on_start: An optional list of notification IDs to call when the run starts. A maximum of 3 destinations can be specified for the on_start property, e.g. [ {"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"}, {"id": "0481e838-0a59-4eff-9541-a4ca6f149574"}, ] - on_success: An optional list of notification IDs to call when the run completes successfully. A maximum of 3 destinations can be specified for the on_success property, e.g. [{"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"}] - on_failure: An optional list of notification IDs to call when the run fails. A maximum of 3 destinations can be specified for the on_failure property, e.g. [{"id": "0481e838-0a59-4eff-9541-a4ca6f149574"}]

None
timeout_seconds Optional[int]

An optional timeout applied to each run of this job. The default behavior is to have no timeout, e.g. 86400.

None
schedule CronSchedule

An optional periodic schedule for this job. The default behavior is that the job only runs when triggered by clicking “Run Now” in the Jobs UI or sending an API request to runNow. Key-values: - quartz_cron_expression: A Cron expression using Quartz syntax that describes the schedule for a job. See Cron Trigger for details. This field is required, e.g. 20 30 * * * ?. - timezone_id: A Java timezone ID. The schedule for a job is resolved with respect to this timezone. See Java TimeZone for details. This field is required, e.g. Europe/London. - pause_status: Indicate whether this schedule is paused or not, e.g. PAUSED.

None
max_concurrent_runs Optional[int]

An optional maximum allowed number of concurrent runs of the job. Set this value if you want to be able to execute multiple runs of the same job concurrently. This is useful for example if you trigger your job on a frequent schedule and want to allow consecutive runs to overlap with each other, or if you want to trigger multiple runs which differ by their input parameters. This setting affects only new runs. For example, suppose the job’s concurrency is 4 and there are 4 concurrent active runs. Then setting the concurrency to 3 won’t kill any of the active runs. However, from then on, new runs are skipped unless there are fewer than 3 active runs. This value cannot exceed 1000. Setting this value to 0 causes all new runs to be skipped. The default behavior is to allow only 1 concurrent run, e.g. 10.

None
git_source GitSource

This functionality is in Public Preview. An optional specification for a remote repository containing the notebooks used by this job's notebook tasks, e.g. { "git_url": "https://github.com/databricks/databricks-cli", "git_branch": "main", "git_provider": "gitHub", } Key-values: - git_url: URL of the repository to be cloned by this job. The maximum length is 300 characters, e.g. https://github.com/databricks/databricks-cli. - git_provider: Unique identifier of the service used to host the Git repository. The value is case insensitive, e.g. github. - git_branch: Name of the branch to be checked out and used by this job. This field cannot be specified in conjunction with git_tag or git_commit. The maximum length is 255 characters, e.g. main. - git_tag: Name of the tag to be checked out and used by this job. This field cannot be specified in conjunction with git_branch or git_commit. The maximum length is 255 characters, e.g. release-1.0.0. - git_commit: Commit to be checked out and used by this job. This field cannot be specified in conjunction with git_branch or git_tag. The maximum length is 64 characters, e.g. e0056d01. - git_snapshot: Read-only state of the remote repository at the time the job was run. This field is only included on job runs.

None
format Optional[str]

Used to tell what is the format of the job. This field is ignored in Create/Update/Reset calls. When using the Jobs API 2.1 this value is always set to 'MULTI_TASK', e.g. MULTI_TASK.

None
access_control_list Optional[List[AccessControlRequest]]

List of permissions to set on the job.

None
parameters Optional[List[JobParameter]]

Job-level parameter definitions.

None

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- job_id: int

API Endpoint:

/2.1/jobs/create

API Responses:

Response Description
200 Job was created successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
@task
async def jobs_create(
    databricks_credentials: "DatabricksCredentials",
    name: str = "Untitled",
    tags: Dict = None,
    tasks: Optional[List["models.JobTaskSettings"]] = None,
    job_clusters: Optional[List["models.JobCluster"]] = None,
    email_notifications: "models.JobEmailNotifications" = None,
    webhook_notifications: "models.WebhookNotifications" = None,
    timeout_seconds: Optional[int] = None,
    schedule: "models.CronSchedule" = None,
    max_concurrent_runs: Optional[int] = None,
    git_source: "models.GitSource" = None,
    format: Optional[str] = None,
    access_control_list: Optional[List["models.AccessControlRequest"]] = None,
    parameters: Optional[List["models.JobParameter"]] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Create a new job.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        name:
            An optional name for the job, e.g. `A multitask job`.
        tags:
            A map of tags associated with the job. These are forwarded to the
            cluster as cluster tags for jobs clusters, and are subject
            to the same limitations as cluster tags. A maximum of 25
            tags can be added to the job, e.g.
            ```
            {"cost-center": "engineering", "team": "jobs"}
            ```
        tasks:
            A list of task specifications to be executed by this job, e.g.
            ```
            [
                {
                    "task_key": "Sessionize",
                    "description": "Extracts session data from events",
                    "depends_on": [],
                    "existing_cluster_id": "0923-164208-meows279",
                    "spark_jar_task": {
                        "main_class_name": "com.databricks.Sessionize",
                        "parameters": ["--data", "dbfs:/path/to/data.json"],
                    },
                    "libraries": [{"jar": "dbfs:/mnt/databricks/Sessionize.jar"}],
                    "timeout_seconds": 86400,
                    "max_retries": 3,
                    "min_retry_interval_millis": 2000,
                    "retry_on_timeout": False,
                },
                {
                    "task_key": "Orders_Ingest",
                    "description": "Ingests order data",
                    "depends_on": [],
                    "job_cluster_key": "auto_scaling_cluster",
                    "spark_jar_task": {
                        "main_class_name": "com.databricks.OrdersIngest",
                        "parameters": ["--data", "dbfs:/path/to/order-data.json"],
                    },
                    "libraries": [{"jar": "dbfs:/mnt/databricks/OrderIngest.jar"}],
                    "timeout_seconds": 86400,
                    "max_retries": 3,
                    "min_retry_interval_millis": 2000,
                    "retry_on_timeout": False,
                },
                {
                    "task_key": "Match",
                    "description": "Matches orders with user sessions",
                    "depends_on": [
                        {"task_key": "Orders_Ingest"},
                        {"task_key": "Sessionize"},
                    ],
                    "new_cluster": {
                        "spark_version": "7.3.x-scala2.12",
                        "node_type_id": "i3.xlarge",
                        "spark_conf": {"spark.speculation": True},
                        "aws_attributes": {
                            "availability": "SPOT",
                            "zone_id": "us-west-2a",
                        },
                        "autoscale": {"min_workers": 2, "max_workers": 16},
                    },
                    "notebook_task": {
                        "notebook_path": "/Users/user.name@databricks.com/Match",
                        "source": "WORKSPACE",
                        "base_parameters": {"name": "John Doe", "age": "35"},
                    },
                    "timeout_seconds": 86400,
                    "max_retries": 3,
                    "min_retry_interval_millis": 2000,
                    "retry_on_timeout": False,
                },
            ]
            ```
        job_clusters:
            A list of job cluster specifications that can be shared and reused by
            tasks of this job. Libraries cannot be declared in a shared
            job cluster. You must declare dependent libraries in task
            settings, e.g.
            ```
            [
                {
                    "job_cluster_key": "auto_scaling_cluster",
                    "new_cluster": {
                        "spark_version": "7.3.x-scala2.12",
                        "node_type_id": "i3.xlarge",
                        "spark_conf": {"spark.speculation": True},
                        "aws_attributes": {
                            "availability": "SPOT",
                            "zone_id": "us-west-2a",
                        },
                        "autoscale": {"min_workers": 2, "max_workers": 16},
                    },
                }
            ]
            ```
        email_notifications:
            An optional set of email addresses that is notified when runs of this
            job begin or complete as well as when this job is deleted.
            The default behavior is to not send any emails. Key-values:
            - on_start:
                A list of email addresses to be notified when a run begins.
                If not specified on job creation, reset, or update, the list
                is empty, and notifications are not sent, e.g.
                ```
                ["user.name@databricks.com"]
                ```
            - on_success:
                A list of email addresses to be notified when a run
                successfully completes. A run is considered to have
                completed successfully if it ends with a `TERMINATED`
                `life_cycle_state` and a `SUCCESSFUL` result_state. If not
                specified on job creation, reset, or update, the list is
                empty, and notifications are not sent, e.g.
                ```
                ["user.name@databricks.com"]
                ```
            - on_failure:
                A list of email addresses to notify when a run completes
                unsuccessfully. A run is considered unsuccessful if it ends
                with an `INTERNAL_ERROR` `life_cycle_state` or a `SKIPPED`,
                `FAILED`, or `TIMED_OUT` `result_state`. If not specified on
                job creation, reset, or update, or the list is empty, then
                notifications are not sent. Job-level failure notifications
                are sent only once after the entire job run (including all
                of its retries) has failed. Notifications are not sent when
                failed job runs are retried. To receive a failure
                notification after every failed task (including every failed
                retry), use task-level notifications instead, e.g.
                ```
                ["user.name@databricks.com"]
                ```
            - no_alert_for_skipped_runs:
                If true, do not send email to recipients specified in
                `on_failure` if the run is skipped.
        webhook_notifications:
            A collection of system notification IDs to notify when runs of this job
            begin or complete. The default behavior is to not send any
            system notifications. Key-values:
            - on_start:
                An optional list of notification IDs to call when the run
                starts. A maximum of 3 destinations can be specified for the
                `on_start` property, e.g.
                ```
                [
                    {"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"},
                    {"id": "0481e838-0a59-4eff-9541-a4ca6f149574"},
                ]
                ```
            - on_success:
                An optional list of notification IDs to call when the run
                completes successfully. A maximum of 3 destinations can be
                specified for the `on_success` property, e.g.
                ```
                [{"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"}]
                ```
            - on_failure:
                An optional list of notification IDs to call when the run
                fails. A maximum of 3 destinations can be specified for the
                `on_failure` property, e.g.
                ```
                [{"id": "0481e838-0a59-4eff-9541-a4ca6f149574"}]
                ```
        timeout_seconds:
            An optional timeout applied to each run of this job. The default
            behavior is to have no timeout, e.g. `86400`.
        schedule:
            An optional periodic schedule for this job. The default behavior is that
            the job only runs when triggered by clicking “Run Now” in
            the Jobs UI or sending an API request to `runNow`. Key-values:
            - quartz_cron_expression:
                A Cron expression using Quartz syntax that describes the
                schedule for a job. See [Cron Trigger](http://www.quartz-
                scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)
                for details. This field is required, e.g. `20 30 * * * ?`.
            - timezone_id:
                A Java timezone ID. The schedule for a job is resolved with
                respect to this timezone. See [Java
                TimeZone](https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html)
                for details. This field is required, e.g. `Europe/London`.
            - pause_status:
                Indicate whether this schedule is paused or not, e.g.
                `PAUSED`.
        max_concurrent_runs:
            An optional maximum allowed number of concurrent runs of the job.  Set
            this value if you want to be able to execute multiple runs
            of the same job concurrently. This is useful for example if
            you trigger your job on a frequent schedule and want to
            allow consecutive runs to overlap with each other, or if you
            want to trigger multiple runs which differ by their input
            parameters.  This setting affects only new runs. For
            example, suppose the job’s concurrency is 4 and there are 4
            concurrent active runs. Then setting the concurrency to 3
            won’t kill any of the active runs. However, from then on,
            new runs are skipped unless there are fewer than 3 active
            runs.  This value cannot exceed 1000\. Setting this value to
            0 causes all new runs to be skipped. The default behavior is
            to allow only 1 concurrent run, e.g. `10`.
        git_source:
            This functionality is in Public Preview.  An optional specification for
            a remote repository containing the notebooks used by this
            job's notebook tasks, e.g.
            ```
            {
                "git_url": "https://github.com/databricks/databricks-cli",
                "git_branch": "main",
                "git_provider": "gitHub",
            }
            ``` Key-values:
            - git_url:
                URL of the repository to be cloned by this job. The maximum
                length is 300 characters, e.g.
                `https://github.com/databricks/databricks-cli`.
            - git_provider:
                Unique identifier of the service used to host the Git
                repository. The value is case insensitive, e.g. `github`.
            - git_branch:
                Name of the branch to be checked out and used by this job.
                This field cannot be specified in conjunction with git_tag
                or git_commit. The maximum length is 255 characters, e.g.
                `main`.
            - git_tag:
                Name of the tag to be checked out and used by this job. This
                field cannot be specified in conjunction with git_branch or
                git_commit. The maximum length is 255 characters, e.g.
                `release-1.0.0`.
            - git_commit:
                Commit to be checked out and used by this job. This field
                cannot be specified in conjunction with git_branch or
                git_tag. The maximum length is 64 characters, e.g.
                `e0056d01`.
            - git_snapshot:
                Read-only state of the remote repository at the time the job was run.
                            This field is only included on job runs.
        format:
            Used to tell what is the format of the job. This field is ignored in
            Create/Update/Reset calls. When using the Jobs API 2.1 this
            value is always set to `'MULTI_TASK'`, e.g. `MULTI_TASK`.
        access_control_list:
            List of permissions to set on the job.
        parameters:
            Job-level parameter definitions.

    Returns:
        Upon success, a dict of the response. </br>- `job_id: int`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/create`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Job was created successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/create"  # noqa

    responses = {
        200: "Job was created successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "name": name,
        "tags": tags,
        "tasks": tasks,
        "job_clusters": job_clusters,
        "email_notifications": email_notifications,
        "webhook_notifications": webhook_notifications,
        "timeout_seconds": timeout_seconds,
        "schedule": schedule,
        "max_concurrent_runs": max_concurrent_runs,
        "git_source": git_source,
        "format": format,
        "access_control_list": access_control_list,
        "parameters": parameters,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_delete(databricks_credentials, job_id=None) async

Deletes a job.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
job_id Optional[int]

The canonical identifier of the job to delete. This field is required, e.g. 11223344.

None

Returns:

Type Description
Dict[str, Any]

Upon success, an empty dict.

API Endpoint:

/2.1/jobs/delete

API Responses:

Response Description
200 Job was deleted successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
@task
async def jobs_delete(
    databricks_credentials: "DatabricksCredentials",
    job_id: Optional[int] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Deletes a job.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        job_id:
            The canonical identifier of the job to delete. This field is required,
            e.g. `11223344`.

    Returns:
        Upon success, an empty dict.

    <h4>API Endpoint:</h4>
    `/2.1/jobs/delete`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Job was deleted successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/delete"  # noqa

    responses = {
        200: "Job was deleted successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "job_id": job_id,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_get(job_id, databricks_credentials) async

Retrieves the details for a single job.

Parameters:

Name Type Description Default
job_id int

The canonical identifier of the job to retrieve information about. This field is required.

required
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- job_id: int
- creator_user_name: str
- run_as_user_name: str
- settings: "models.JobSettings"
- created_time: int

API Endpoint:

/2.1/jobs/get

API Responses:

Response Description
200 Job was retrieved successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
@task
async def jobs_get(
    job_id: int,
    databricks_credentials: "DatabricksCredentials",
) -> Dict[str, Any]:  # pragma: no cover
    """
    Retrieves the details for a single job.

    Args:
        job_id:
            The canonical identifier of the job to retrieve information about. This
            field is required.
        databricks_credentials:
            Credentials to use for authentication with Databricks.

    Returns:
        Upon success, a dict of the response. </br>- `job_id: int`</br>- `creator_user_name: str`</br>- `run_as_user_name: str`</br>- `settings: "models.JobSettings"`</br>- `created_time: int`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/get`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Job was retrieved successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/get"  # noqa

    responses = {
        200: "Job was retrieved successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    params = {
        "job_id": job_id,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.GET,
        params=params,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_list(databricks_credentials, limit=20, offset=0, name=None, expand_tasks=False) async

Retrieves a list of jobs.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
limit int

The number of jobs to return. This value must be greater than 0 and less or equal to 25. The default value is 20.

20
offset int

The offset of the first job to return, relative to the most recently created job.

0
name Optional[str]

A filter on the list based on the exact (case insensitive) job name.

None
expand_tasks bool

Whether to include task and cluster details in the response.

False

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- jobs: List["models.Job"]
- has_more: bool

API Endpoint:

/2.1/jobs/list

API Responses:

Response Description
200 List of jobs was retrieved successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
@task
async def jobs_list(
    databricks_credentials: "DatabricksCredentials",
    limit: int = 20,
    offset: int = 0,
    name: Optional[str] = None,
    expand_tasks: bool = False,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Retrieves a list of jobs.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        limit:
            The number of jobs to return. This value must be greater than 0 and less
            or equal to 25. The default value is 20.
        offset:
            The offset of the first job to return, relative to the most recently
            created job.
        name:
            A filter on the list based on the exact (case insensitive) job name.
        expand_tasks:
            Whether to include task and cluster details in the response.

    Returns:
        Upon success, a dict of the response. </br>- `jobs: List["models.Job"]`</br>- `has_more: bool`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/list`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | List of jobs was retrieved successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/list"  # noqa

    responses = {
        200: "List of jobs was retrieved successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    params = {
        "limit": limit,
        "offset": offset,
        "name": name,
        "expand_tasks": expand_tasks,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.GET,
        params=params,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_reset(databricks_credentials, job_id=None, new_settings=None) async

Overwrites all the settings for a specific job. Use the Update endpoint to update job settings partially.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
job_id Optional[int]

The canonical identifier of the job to reset. This field is required, e.g. 11223344.

None
new_settings JobSettings

The new settings of the job. These settings completely replace the old settings. Changes to the field JobSettings.timeout_seconds are applied to active runs. Changes to other fields are applied to future runs only. Key-values: - name: An optional name for the job, e.g. A multitask job. - tags: A map of tags associated with the job. These are forwarded to the cluster as cluster tags for jobs clusters, and are subject to the same limitations as cluster tags. A maximum of 25 tags can be added to the job, e.g. {"cost-center": "engineering", "team": "jobs"} - tasks: A list of task specifications to be executed by this job, e.g. [ { "task_key": "Sessionize", "description": "Extracts session data from events", "depends_on": [], "existing_cluster_id": "0923-164208-meows279", "spark_jar_task": { "main_class_name": "com.databricks.Sessionize", "parameters": [ "--data", "dbfs:/path/to/data.json", ], }, "libraries": [ {"jar": "dbfs:/mnt/databricks/Sessionize.jar"} ], "timeout_seconds": 86400, "max_retries": 3, "min_retry_interval_millis": 2000, "retry_on_timeout": False, }, { "task_key": "Orders_Ingest", "description": "Ingests order data", "depends_on": [], "job_cluster_key": "auto_scaling_cluster", "spark_jar_task": { "main_class_name": "com.databricks.OrdersIngest", "parameters": [ "--data", "dbfs:/path/to/order-data.json", ], }, "libraries": [ {"jar": "dbfs:/mnt/databricks/OrderIngest.jar"} ], "timeout_seconds": 86400, "max_retries": 3, "min_retry_interval_millis": 2000, "retry_on_timeout": False, }, { "task_key": "Match", "description": "Matches orders with user sessions", "depends_on": [ {"task_key": "Orders_Ingest"}, {"task_key": "Sessionize"}, ], "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "i3.xlarge", "spark_conf": {"spark.speculation": True}, "aws_attributes": { "availability": "SPOT", "zone_id": "us-west-2a", }, "autoscale": { "min_workers": 2, "max_workers": 16, }, }, "notebook_task": { "notebook_path": "/Users/user.name@databricks.com/Match", "source": "WORKSPACE", "base_parameters": { "name": "John Doe", "age": "35", }, }, "timeout_seconds": 86400, "max_retries": 3, "min_retry_interval_millis": 2000, "retry_on_timeout": False, }, ] - job_clusters: A list of job cluster specifications that can be shared and reused by tasks of this job. Libraries cannot be declared in a shared job cluster. You must declare dependent libraries in task settings, e.g. [ { "job_cluster_key": "auto_scaling_cluster", "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "i3.xlarge", "spark_conf": {"spark.speculation": True}, "aws_attributes": { "availability": "SPOT", "zone_id": "us-west-2a", }, "autoscale": { "min_workers": 2, "max_workers": 16, }, }, } ] - email_notifications: An optional set of email addresses that is notified when runs of this job begin or complete as well as when this job is deleted. The default behavior is to not send any emails. - webhook_notifications: A collection of system notification IDs to notify when runs of this job begin or complete. The default behavior is to not send any system notifications. - timeout_seconds: An optional timeout applied to each run of this job. The default behavior is to have no timeout, e.g. 86400. - schedule: An optional periodic schedule for this job. The default behavior is that the job only runs when triggered by clicking “Run Now” in the Jobs UI or sending an API request to runNow. - max_concurrent_runs: An optional maximum allowed number of concurrent runs of the job. Set this value if you want to be able to execute multiple runs of the same job concurrently. This is useful for example if you trigger your job on a frequent schedule and want to allow consecutive runs to overlap with each other, or if you want to trigger multiple runs which differ by their input parameters. This setting affects only new runs. For example, suppose the job’s concurrency is 4 and there are 4 concurrent active runs. Then setting the concurrency to 3 won’t kill any of the active runs. However, from then on, new runs are skipped unless there are fewer than 3 active runs. This value cannot exceed 1000. Setting this value to 0 causes all new runs to be skipped. The default behavior is to allow only 1 concurrent run, e.g. 10. - git_source: This functionality is in Public Preview. An optional specification for a remote repository containing the notebooks used by this job's notebook tasks, e.g. { "git_url": "https://github.com/databricks/databricks-cli", "git_branch": "main", "git_provider": "gitHub", } - format: Used to tell what is the format of the job. This field is ignored in Create/Update/Reset calls. When using the Jobs API 2.1 this value is always set to 'MULTI_TASK', e.g. MULTI_TASK. - job_settings: Job-level parameter definitions.

None

Returns:

Type Description
Dict[str, Any]

Upon success, an empty dict.

API Endpoint:

/2.1/jobs/reset

API Responses:

Response Description
200 Job was overwritten successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
@task
async def jobs_reset(
    databricks_credentials: "DatabricksCredentials",
    job_id: Optional[int] = None,
    new_settings: "models.JobSettings" = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Overwrites all the settings for a specific job. Use the Update endpoint to
    update job settings partially.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        job_id:
            The canonical identifier of the job to reset. This field is required,
            e.g. `11223344`.
        new_settings:
            The new settings of the job. These settings completely replace the old
            settings.  Changes to the field
            `JobSettings.timeout_seconds` are applied to active runs.
            Changes to other fields are applied to future runs only. Key-values:
            - name:
                An optional name for the job, e.g. `A multitask job`.
            - tags:
                A map of tags associated with the job. These are forwarded
                to the cluster as cluster tags for jobs clusters, and are
                subject to the same limitations as cluster tags. A maximum
                of 25 tags can be added to the job, e.g.
                ```
                {"cost-center": "engineering", "team": "jobs"}
                ```
            - tasks:
                A list of task specifications to be executed by this job, e.g.
                ```
                [
                    {
                        "task_key": "Sessionize",
                        "description": "Extracts session data from events",
                        "depends_on": [],
                        "existing_cluster_id": "0923-164208-meows279",
                        "spark_jar_task": {
                            "main_class_name": "com.databricks.Sessionize",
                            "parameters": [
                                "--data",
                                "dbfs:/path/to/data.json",
                            ],
                        },
                        "libraries": [
                            {"jar": "dbfs:/mnt/databricks/Sessionize.jar"}
                        ],
                        "timeout_seconds": 86400,
                        "max_retries": 3,
                        "min_retry_interval_millis": 2000,
                        "retry_on_timeout": False,
                    },
                    {
                        "task_key": "Orders_Ingest",
                        "description": "Ingests order data",
                        "depends_on": [],
                        "job_cluster_key": "auto_scaling_cluster",
                        "spark_jar_task": {
                            "main_class_name": "com.databricks.OrdersIngest",
                            "parameters": [
                                "--data",
                                "dbfs:/path/to/order-data.json",
                            ],
                        },
                        "libraries": [
                            {"jar": "dbfs:/mnt/databricks/OrderIngest.jar"}
                        ],
                        "timeout_seconds": 86400,
                        "max_retries": 3,
                        "min_retry_interval_millis": 2000,
                        "retry_on_timeout": False,
                    },
                    {
                        "task_key": "Match",
                        "description": "Matches orders with user sessions",
                        "depends_on": [
                            {"task_key": "Orders_Ingest"},
                            {"task_key": "Sessionize"},
                        ],
                        "new_cluster": {
                            "spark_version": "7.3.x-scala2.12",
                            "node_type_id": "i3.xlarge",
                            "spark_conf": {"spark.speculation": True},
                            "aws_attributes": {
                                "availability": "SPOT",
                                "zone_id": "us-west-2a",
                            },
                            "autoscale": {
                                "min_workers": 2,
                                "max_workers": 16,
                            },
                        },
                        "notebook_task": {
                            "notebook_path": "/Users/user.name@databricks.com/Match",
                            "source": "WORKSPACE",
                            "base_parameters": {
                                "name": "John Doe",
                                "age": "35",
                            },
                        },
                        "timeout_seconds": 86400,
                        "max_retries": 3,
                        "min_retry_interval_millis": 2000,
                        "retry_on_timeout": False,
                    },
                ]
                ```
            - job_clusters:
                A list of job cluster specifications that can be shared and
                reused by tasks of this job. Libraries cannot be declared in
                a shared job cluster. You must declare dependent libraries
                in task settings, e.g.
                ```
                [
                    {
                        "job_cluster_key": "auto_scaling_cluster",
                        "new_cluster": {
                            "spark_version": "7.3.x-scala2.12",
                            "node_type_id": "i3.xlarge",
                            "spark_conf": {"spark.speculation": True},
                            "aws_attributes": {
                                "availability": "SPOT",
                                "zone_id": "us-west-2a",
                            },
                            "autoscale": {
                                "min_workers": 2,
                                "max_workers": 16,
                            },
                        },
                    }
                ]
                ```
            - email_notifications:
                An optional set of email addresses that is notified when
                runs of this job begin or complete as well as when this job
                is deleted. The default behavior is to not send any emails.
            - webhook_notifications:
                A collection of system notification IDs to notify when runs
                of this job begin or complete. The default behavior is to
                not send any system notifications.
            - timeout_seconds:
                An optional timeout applied to each run of this job. The
                default behavior is to have no timeout, e.g. `86400`.
            - schedule:
                An optional periodic schedule for this job. The default
                behavior is that the job only runs when triggered by
                clicking “Run Now” in the Jobs UI or sending an API request
                to `runNow`.
            - max_concurrent_runs:
                An optional maximum allowed number of concurrent runs of the
                job.  Set this value if you want to be able to execute
                multiple runs of the same job concurrently. This is useful
                for example if you trigger your job on a frequent schedule
                and want to allow consecutive runs to overlap with each
                other, or if you want to trigger multiple runs which differ
                by their input parameters.  This setting affects only new
                runs. For example, suppose the job’s concurrency is 4 and
                there are 4 concurrent active runs. Then setting the
                concurrency to 3 won’t kill any of the active runs. However,
                from then on, new runs are skipped unless there are fewer
                than 3 active runs.  This value cannot exceed 1000\. Setting
                this value to 0 causes all new runs to be skipped. The
                default behavior is to allow only 1 concurrent run, e.g.
                `10`.
            - git_source:
                This functionality is in Public Preview.  An optional
                specification for a remote repository containing the
                notebooks used by this job's notebook tasks, e.g.
                ```
                {
                    "git_url": "https://github.com/databricks/databricks-cli",
                    "git_branch": "main",
                    "git_provider": "gitHub",
                }
                ```
            - format:
                Used to tell what is the format of the job. This field is
                ignored in Create/Update/Reset calls. When using the Jobs
                API 2.1 this value is always set to `'MULTI_TASK'`, e.g.
                `MULTI_TASK`.
            - job_settings:
                Job-level parameter definitions.

    Returns:
        Upon success, an empty dict.

    <h4>API Endpoint:</h4>
    `/2.1/jobs/reset`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Job was overwritten successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/reset"  # noqa

    responses = {
        200: "Job was overwritten successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "job_id": job_id,
        "new_settings": new_settings,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_run_now(databricks_credentials, job_id=None, idempotency_token=None, jar_params=None, notebook_params=None, python_params=None, spark_submit_params=None, python_named_params=None, pipeline_params=None, sql_params=None, dbt_commands=None, job_parameters=None) async

Run a job and return the run_id of the triggered run.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
job_id Optional[int]

The ID of the job to be executed, e.g. 11223344.

None
idempotency_token Optional[str]

An optional token to guarantee the idempotency of job run requests. If a run with the provided token already exists, the request does not create a new run but returns the ID of the existing run instead. If a run with the provided token is deleted, an error is returned. If you specify the idempotency token, upon failure you can retry until the request succeeds. Databricks guarantees that exactly one run is launched with that idempotency token. This token must have at most 64 characters. For more information, see How to ensure idempotency for jobs, e.g. 8f018174-4792-40d5-bcbc-3e6a527352c8.

None
jar_params Optional[List[str]]

A list of parameters for jobs with Spark JAR tasks, for example 'jar_params': ['john doe', '35']. The parameters are used to invoke the main function of the main class specified in the Spark JAR task. If not specified upon run-now, it defaults to an empty list. jar_params cannot be specified in conjunction with notebook_params. The JSON representation of this field (for example {'jar_params':['john doe','35']}) cannot exceed 10,000 bytes. Use Task parameter variables to set parameters containing information about job runs, e.g.

["john", "doe", "35"]
None
notebook_params Optional[Dict]

A map from keys to values for jobs with notebook task, for example 'notebook_params': {'name': 'john doe', 'age': '35'}. The map is passed to the notebook and is accessible through the dbutils.widgets.get function. If not specified upon run-now, the triggered run uses the job’s base parameters. notebook_params cannot be specified in conjunction with jar_params. Use Task parameter variables to set parameters containing information about job runs. The JSON representation of this field (for example {'notebook_params':{'name':'john doe','age':'35'}}) cannot exceed 10,000 bytes, e.g.

{"name": "john doe", "age": "35"}
None
python_params Optional[List[str]]

A list of parameters for jobs with Python tasks, for example 'python_params': ['john doe', '35']. The parameters are passed to Python file as command-line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The JSON representation of this field (for example {'python_params':['john doe','35']}) cannot exceed 10,000 bytes. Use Task parameter variables to set parameters containing information about job runs. Important These parameters accept only Latin characters (ASCII character set). Using non-ASCII characters returns an error. Examples of invalid, non-ASCII characters are Chinese, Japanese kanjis, and emojis, e.g.

["john doe", "35"]
None
spark_submit_params Optional[List[str]]

A list of parameters for jobs with spark submit task, for example 'spark_submit_params': ['--class', 'org.apache.spark.examples.SparkPi']. The parameters are passed to spark-submit script as command-line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The JSON representation of this field (for example {'python_params':['john doe','35']}) cannot exceed 10,000 bytes. Use Task parameter variables to set parameters containing information about job runs. Important These parameters accept only Latin characters (ASCII character set). Using non-ASCII characters returns an error. Examples of invalid, non-ASCII characters are Chinese, Japanese kanjis, and emojis, e.g.

["--class", "org.apache.spark.examples.SparkPi"]
None
python_named_params Optional[Dict]

A map from keys to values for jobs with Python wheel task, for example 'python_named_params': {'name': 'task', 'data': 'dbfs:/path/to/data.json'}, e.g.

{"name": "task", "data": "dbfs:/path/to/data.json"}
None
pipeline_params Optional[str]
None
sql_params Optional[Dict]

A map from keys to values for SQL tasks, for example 'sql_params': {'name': 'john doe', 'age': '35'}. The SQL alert task does not support custom parameters, e.g.

{"name": "john doe", "age": "35"}
None
dbt_commands Optional[List]

An array of commands to execute for jobs with the dbt task, for example 'dbt_commands': ['dbt deps', 'dbt seed', 'dbt run'], e.g.

["dbt deps", "dbt seed", "dbt run"]
None
job_parameters Optional[Dict]

A map from keys to values for job-level parameters used in the run, for example 'job_parameters': {'param': 'overriding_val'}, e.g.

{"param": "overriding_val"}
None

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- run_id: int
- number_in_job: int

API Endpoint:

/2.1/jobs/run-now

API Responses:

Response Description
200 Run was started successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
@task
async def jobs_run_now(
    databricks_credentials: "DatabricksCredentials",
    job_id: Optional[int] = None,
    idempotency_token: Optional[str] = None,
    jar_params: Optional[List[str]] = None,
    notebook_params: Optional[Dict] = None,
    python_params: Optional[List[str]] = None,
    spark_submit_params: Optional[List[str]] = None,
    python_named_params: Optional[Dict] = None,
    pipeline_params: Optional[str] = None,
    sql_params: Optional[Dict] = None,
    dbt_commands: Optional[List] = None,
    job_parameters: Optional[Dict] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Run a job and return the `run_id` of the triggered run.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        job_id:
            The ID of the job to be executed, e.g. `11223344`.
        idempotency_token:
            An optional token to guarantee the idempotency of job run requests. If a
            run with the provided token already exists, the request does
            not create a new run but returns the ID of the existing run
            instead. If a run with the provided token is deleted, an
            error is returned.  If you specify the idempotency token,
            upon failure you can retry until the request succeeds.
            Databricks guarantees that exactly one run is launched with
            that idempotency token.  This token must have at most 64
            characters.  For more information, see [How to ensure
            idempotency for jobs](https://kb.databricks.com/jobs/jobs-
            idempotency.html), e.g.
            `8f018174-4792-40d5-bcbc-3e6a527352c8`.
        jar_params:
            A list of parameters for jobs with Spark JAR tasks, for example
            `'jar_params': ['john doe', '35']`. The parameters are used
            to invoke the main function of the main class specified in
            the Spark JAR task. If not specified upon `run-now`, it
            defaults to an empty list. jar_params cannot be specified in
            conjunction with notebook_params. The JSON representation of
            this field (for example `{'jar_params':['john doe','35']}`)
            cannot exceed 10,000 bytes.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs, e.g.
            ```
            ["john", "doe", "35"]
            ```
        notebook_params:
            A map from keys to values for jobs with notebook task, for example
            `'notebook_params': {'name': 'john doe', 'age': '35'}`. The
            map is passed to the notebook and is accessible through the
            [dbutils.widgets.get](https://docs.databricks.com/dev-
            tools/databricks-utils.html
            dbutils-widgets) function.  If not specified upon `run-now`,
            the triggered run uses the job’s base parameters.
            notebook_params cannot be specified in conjunction with
            jar_params.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs.  The JSON representation of this
            field (for example `{'notebook_params':{'name':'john
            doe','age':'35'}}`) cannot exceed 10,000 bytes, e.g.
            ```
            {"name": "john doe", "age": "35"}
            ```
        python_params:
            A list of parameters for jobs with Python tasks, for example
            `'python_params': ['john doe', '35']`. The parameters are
            passed to Python file as command-line parameters. If
            specified upon `run-now`, it would overwrite the parameters
            specified in job setting. The JSON representation of this
            field (for example `{'python_params':['john doe','35']}`)
            cannot exceed 10,000 bytes.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs.  Important  These parameters
            accept only Latin characters (ASCII character set). Using
            non-ASCII characters returns an error. Examples of invalid,
            non-ASCII characters are Chinese, Japanese kanjis, and
            emojis, e.g.
            ```
            ["john doe", "35"]
            ```
        spark_submit_params:
            A list of parameters for jobs with spark submit task, for example
            `'spark_submit_params': ['--class',
            'org.apache.spark.examples.SparkPi']`. The parameters are
            passed to spark-submit script as command-line parameters. If
            specified upon `run-now`, it would overwrite the parameters
            specified in job setting. The JSON representation of this
            field (for example `{'python_params':['john doe','35']}`)
            cannot exceed 10,000 bytes.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs.  Important  These parameters
            accept only Latin characters (ASCII character set). Using
            non-ASCII characters returns an error. Examples of invalid,
            non-ASCII characters are Chinese, Japanese kanjis, and
            emojis, e.g.
            ```
            ["--class", "org.apache.spark.examples.SparkPi"]
            ```
        python_named_params:
            A map from keys to values for jobs with Python wheel task, for example
            `'python_named_params': {'name': 'task', 'data':
            'dbfs:/path/to/data.json'}`, e.g.
            ```
            {"name": "task", "data": "dbfs:/path/to/data.json"}
            ```
        pipeline_params:

        sql_params:
            A map from keys to values for SQL tasks, for example `'sql_params':
            {'name': 'john doe', 'age': '35'}`. The SQL alert task does
            not support custom parameters, e.g.
            ```
            {"name": "john doe", "age": "35"}
            ```
        dbt_commands:
            An array of commands to execute for jobs with the dbt task, for example
            `'dbt_commands': ['dbt deps', 'dbt seed', 'dbt run']`, e.g.
            ```
            ["dbt deps", "dbt seed", "dbt run"]
            ```

        job_parameters:
            A map from keys to values for job-level parameters used in the run, for example
             `'job_parameters': {'param': 'overriding_val'}`, e.g.
            ```
            {"param": "overriding_val"}
            ```

    Returns:
        Upon success, a dict of the response. </br>- `run_id: int`</br>- `number_in_job: int`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/run-now`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run was started successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/run-now"  # noqa

    responses = {
        200: "Run was started successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "job_id": job_id,
        "idempotency_token": idempotency_token,
        "jar_params": jar_params,
        "notebook_params": notebook_params,
        "python_params": python_params,
        "spark_submit_params": spark_submit_params,
        "python_named_params": python_named_params,
        "pipeline_params": pipeline_params,
        "sql_params": sql_params,
        "dbt_commands": dbt_commands,
        "job_parameters": job_parameters,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_cancel(databricks_credentials, run_id=None) async

Cancels a job run. The run is canceled asynchronously, so it may still be running when this request completes.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
run_id Optional[int]

This field is required, e.g. 455644833.

None

Returns:

Type Description
Dict[str, Any]

Upon success, an empty dict.

API Endpoint:

/2.1/jobs/runs/cancel

API Responses:

Response Description
200 Run was cancelled successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
@task
async def jobs_runs_cancel(
    databricks_credentials: "DatabricksCredentials",
    run_id: Optional[int] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Cancels a job run. The run is canceled asynchronously, so it may still be
    running when this request completes.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        run_id:
            This field is required, e.g. `455644833`.

    Returns:
        Upon success, an empty dict.

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/cancel`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run was cancelled successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/cancel"  # noqa

    responses = {
        200: "Run was cancelled successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "run_id": run_id,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_cancel_all(databricks_credentials, job_id=None) async

Cancels all active runs of a job. The runs are canceled asynchronously, so it doesn't prevent new runs from being started.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
job_id Optional[int]

The canonical identifier of the job to cancel all runs of. This field is required, e.g. 11223344.

None

Returns:

Type Description
Dict[str, Any]

Upon success, an empty dict.

API Endpoint:

/2.1/jobs/runs/cancel-all

API Responses:

Response Description
200 All runs were cancelled successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
@task
async def jobs_runs_cancel_all(
    databricks_credentials: "DatabricksCredentials",
    job_id: Optional[int] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Cancels all active runs of a job. The runs are canceled asynchronously, so it
    doesn't prevent new runs from being started.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        job_id:
            The canonical identifier of the job to cancel all runs of. This field is
            required, e.g. `11223344`.

    Returns:
        Upon success, an empty dict.

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/cancel-all`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | All runs were cancelled successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/cancel-all"  # noqa

    responses = {
        200: "All runs were cancelled successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "job_id": job_id,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_delete(databricks_credentials, run_id=None) async

Deletes a non-active run. Returns an error if the run is active.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
run_id Optional[int]

The canonical identifier of the run for which to retrieve the metadata, e.g. 455644833.

None

Returns:

Type Description
Dict[str, Any]

Upon success, an empty dict.

API Endpoint:

/2.1/jobs/runs/delete

API Responses:

Response Description
200 Run was deleted successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
@task
async def jobs_runs_delete(
    databricks_credentials: "DatabricksCredentials",
    run_id: Optional[int] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Deletes a non-active run. Returns an error if the run is active.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        run_id:
            The canonical identifier of the run for which to retrieve the metadata,
            e.g. `455644833`.

    Returns:
        Upon success, an empty dict.

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/delete`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run was deleted successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/delete"  # noqa

    responses = {
        200: "Run was deleted successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "run_id": run_id,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_export(run_id, databricks_credentials, views_to_export=None) async

Export and retrieve the job run task.

Parameters:

Name Type Description Default
run_id int

The canonical identifier for the run. This field is required.

required
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
views_to_export Optional[ViewsToExport]

Which views to export (CODE, DASHBOARDS, or ALL). Defaults to CODE.

None

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- views: List["models.ViewItem"]

API Endpoint:

/2.0/jobs/runs/export

API Responses:

Response Description
200 Run was exported successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@task
async def jobs_runs_export(
    run_id: int,
    databricks_credentials: "DatabricksCredentials",
    views_to_export: Optional["models.ViewsToExport"] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Export and retrieve the job run task.

    Args:
        run_id:
            The canonical identifier for the run. This field is required.
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        views_to_export:
            Which views to export (CODE, DASHBOARDS, or ALL). Defaults to CODE.

    Returns:
        Upon success, a dict of the response. </br>- `views: List["models.ViewItem"]`</br>

    <h4>API Endpoint:</h4>
    `/2.0/jobs/runs/export`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run was exported successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.0/jobs/runs/export"  # noqa

    responses = {
        200: "Run was exported successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    params = {
        "run_id": run_id,
        "views_to_export": views_to_export,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.GET,
        params=params,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_get(run_id, databricks_credentials, include_history=None) async

Retrieve the metadata of a run.

Parameters:

Name Type Description Default
run_id int

The canonical identifier of the run for which to retrieve the metadata. This field is required.

required
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
include_history Optional[bool]

Whether to include the repair history in the response.

None

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- job_id: int
- run_id: int
- number_in_job: int
- creator_user_name: str
- original_attempt_run_id: int
- state: "models.RunState"
- schedule: "models.CronSchedule"
- tasks: List["models.RunTask"]
- job_clusters: List["models.JobCluster"]
- cluster_spec: "models.ClusterSpec"
- cluster_instance: "models.ClusterInstance"
- git_source: "models.GitSource"
- overriding_parameters: "models.RunParameters"
- start_time: int
- setup_duration: int
- execution_duration: int
- cleanup_duration: int
- end_time: int
- trigger: "models.TriggerType"
- run_name: str
- run_page_url: str
- run_type: "models.RunType"
- attempt_number: int
- repair_history: List["models.RepairHistoryItem"]
- job_parameters: List["models.RunJobParameter]"

API Endpoint:

/2.1/jobs/runs/get

API Responses:

Response Description
200 Run was retrieved successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
@task
async def jobs_runs_get(
    run_id: int,
    databricks_credentials: "DatabricksCredentials",
    include_history: Optional[bool] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Retrieve the metadata of a run.

    Args:
        run_id:
            The canonical identifier of the run for which to retrieve the metadata.
            This field is required.
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        include_history:
            Whether to include the repair history in the response.

    Returns:
        Upon success, a dict of the response. </br>- `job_id: int`</br>- `run_id: int`</br>- `number_in_job: int`</br>- `creator_user_name: str`</br>- `original_attempt_run_id: int`</br>- `state: "models.RunState"`</br>- `schedule: "models.CronSchedule"`</br>- `tasks: List["models.RunTask"]`</br>- `job_clusters: List["models.JobCluster"]`</br>- `cluster_spec: "models.ClusterSpec"`</br>- `cluster_instance: "models.ClusterInstance"`</br>- `git_source: "models.GitSource"`</br>- `overriding_parameters: "models.RunParameters"`</br>- `start_time: int`</br>- `setup_duration: int`</br>- `execution_duration: int`</br>- `cleanup_duration: int`</br>- `end_time: int`</br>- `trigger: "models.TriggerType"`</br>- `run_name: str`</br>- `run_page_url: str`</br>- `run_type: "models.RunType"`</br>- `attempt_number: int`</br>- `repair_history: List["models.RepairHistoryItem"]`</br>- `job_parameters: List["models.RunJobParameter]"`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/get`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run was retrieved successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/get"  # noqa

    responses = {
        200: "Run was retrieved successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    params = {
        "run_id": run_id,
        "include_history": include_history,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.GET,
        params=params,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_get_output(run_id, databricks_credentials) async

Retrieve the output and metadata of a single task run. When a notebook task returns a value through the dbutils.notebook.exit() call, you can use this endpoint to retrieve that value. Databricks restricts this API to return the first 5 MB of the output. To return a larger result, you can store job results in a cloud storage service. This endpoint validates that the run_id parameter is valid and returns an HTTP status code 400 if the run_id parameter is invalid. Runs are automatically removed after 60 days. If you to want to reference them beyond 60 days, you must save old run results before they expire. To export using the UI, see Export job run results. To export using the Jobs API, see Runs export.

Parameters:

Name Type Description Default
run_id int

The canonical identifier for the run. This field is required.

required
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- notebook_output: "models.NotebookOutput"
- sql_output: "models.SqlOutput"
- dbt_output: "models.DbtOutput"
- logs: str
- logs_truncated: bool
- error: str
- error_trace: str
- metadata: "models.Run"

API Endpoint:

/2.1/jobs/runs/get-output

API Responses:

Response Description
200 Run output was retrieved successfully.
400 A job run with multiple tasks was provided.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
@task
async def jobs_runs_get_output(
    run_id: int,
    databricks_credentials: "DatabricksCredentials",
) -> Dict[str, Any]:  # pragma: no cover
    """
    Retrieve the output and metadata of a single task run. When a notebook task
    returns a value through the dbutils.notebook.exit() call, you can use this
    endpoint to retrieve that value. Databricks restricts this API to return the
    first 5 MB of the output. To return a larger result, you can store job
    results in a cloud storage service. This endpoint validates that the run_id
    parameter is valid and returns an HTTP status code 400 if the run_id
    parameter is invalid. Runs are automatically removed after 60 days. If you
    to want to reference them beyond 60 days, you must save old run results
    before they expire. To export using the UI, see Export job run results. To
    export using the Jobs API, see Runs export.

    Args:
        run_id:
            The canonical identifier for the run. This field is required.
        databricks_credentials:
            Credentials to use for authentication with Databricks.

    Returns:
        Upon success, a dict of the response. </br>- `notebook_output: "models.NotebookOutput"`</br>- `sql_output: "models.SqlOutput"`</br>- `dbt_output: "models.DbtOutput"`</br>- `logs: str`</br>- `logs_truncated: bool`</br>- `error: str`</br>- `error_trace: str`</br>- `metadata: "models.Run"`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/get-output`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run output was retrieved successfully. |
    | 400 | A job run with multiple tasks was provided. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/get-output"  # noqa

    responses = {
        200: "Run output was retrieved successfully.",  # noqa
        400: "A job run with multiple tasks was provided.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    params = {
        "run_id": run_id,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.GET,
        params=params,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_list(databricks_credentials, active_only=False, completed_only=False, job_id=None, offset=0, limit=25, run_type=None, expand_tasks=False, start_time_from=None, start_time_to=None) async

List runs in descending order by start time.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
active_only bool

If active_only is true, only active runs are included in the results; otherwise, lists both active and completed runs. An active run is a run in the PENDING, RUNNING, or TERMINATING. This field cannot be true when completed_only is true.

False
completed_only bool

If completed_only is true, only completed runs are included in the results; otherwise, lists both active and completed runs. This field cannot be true when active_only is true.

False
job_id Optional[int]

The job for which to list runs. If omitted, the Jobs service lists runs from all jobs.

None
offset int

The offset of the first run to return, relative to the most recent run.

0
limit int

The number of runs to return. This value must be greater than 0 and less than 25. The default value is 25. If a request specifies a limit of 0, the service instead uses the maximum limit.

25
run_type Optional[str]

The type of runs to return. For a description of run types, see Run.

None
expand_tasks bool

Whether to include task and cluster details in the response.

False
start_time_from Optional[int]

Show runs that started at or after this value. The value must be a UTC timestamp in milliseconds. Can be combined with start_time_to to filter by a time range.

None
start_time_to Optional[int]

Show runs that started at or before this value. The value must be a UTC timestamp in milliseconds. Can be combined with start_time_from to filter by a time range.

None

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- runs: List["models.Run"]
- has_more: bool

API Endpoint:

/2.1/jobs/runs/list

API Responses:

Response Description
200 List of runs was retrieved successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
@task
async def jobs_runs_list(
    databricks_credentials: "DatabricksCredentials",
    active_only: bool = False,
    completed_only: bool = False,
    job_id: Optional[int] = None,
    offset: int = 0,
    limit: int = 25,
    run_type: Optional[str] = None,
    expand_tasks: bool = False,
    start_time_from: Optional[int] = None,
    start_time_to: Optional[int] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    List runs in descending order by start time.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        active_only:
            If active_only is `true`, only active runs are included in the results;
            otherwise, lists both active and completed runs. An active
            run is a run in the `PENDING`, `RUNNING`, or `TERMINATING`.
            This field cannot be `true` when completed_only is `true`.
        completed_only:
            If completed_only is `true`, only completed runs are included in the
            results; otherwise, lists both active and completed runs.
            This field cannot be `true` when active_only is `true`.
        job_id:
            The job for which to list runs. If omitted, the Jobs service lists runs
            from all jobs.
        offset:
            The offset of the first run to return, relative to the most recent run.
        limit:
            The number of runs to return. This value must be greater than 0 and less
            than 25\. The default value is 25\. If a request specifies a
            limit of 0, the service instead uses the maximum limit.
        run_type:
            The type of runs to return. For a description of run types, see
            [Run](https://docs.databricks.com/dev-
            tools/api/latest/jobs.html
            operation/JobsRunsGet).
        expand_tasks:
            Whether to include task and cluster details in the response.
        start_time_from:
            Show runs that started _at or after_ this value. The value must be a UTC
            timestamp in milliseconds. Can be combined with
            _start_time_to_ to filter by a time range.
        start_time_to:
            Show runs that started _at or before_ this value. The value must be a
            UTC timestamp in milliseconds. Can be combined with
            _start_time_from_ to filter by a time range.

    Returns:
        Upon success, a dict of the response. </br>- `runs: List["models.Run"]`</br>- `has_more: bool`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/list`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | List of runs was retrieved successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/list"  # noqa

    responses = {
        200: "List of runs was retrieved successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    params = {
        "active_only": active_only,
        "completed_only": completed_only,
        "job_id": job_id,
        "offset": offset,
        "limit": limit,
        "run_type": run_type,
        "expand_tasks": expand_tasks,
        "start_time_from": start_time_from,
        "start_time_to": start_time_to,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.GET,
        params=params,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_repair(databricks_credentials, run_id=None, rerun_tasks=None, latest_repair_id=None, rerun_all_failed_tasks=False, jar_params=None, notebook_params=None, python_params=None, spark_submit_params=None, python_named_params=None, pipeline_params=None, sql_params=None, dbt_commands=None, job_parameters=None) async

Re-run one or more tasks. Tasks are re-run as part of the original job run, use the current job and task settings, and can be viewed in the history for the original job run.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
run_id Optional[int]

The job run ID of the run to repair. The run must not be in progress, e.g. 455644833.

None
rerun_tasks Optional[List[str]]

The task keys of the task runs to repair, e.g.

["task0", "task1"]
None
latest_repair_id Optional[int]

The ID of the latest repair. This parameter is not required when repairing a run for the first time, but must be provided on subsequent requests to repair the same run, e.g. 734650698524280.

None
rerun_all_failed_tasks bool

If true, repair all failed tasks. Only one of rerun_tasks or rerun_all_failed_tasks can be used.

False
jar_params Optional[List[str]]

A list of parameters for jobs with Spark JAR tasks, for example 'jar_params': ['john doe', '35']. The parameters are used to invoke the main function of the main class specified in the Spark JAR task. If not specified upon run-now, it defaults to an empty list. jar_params cannot be specified in conjunction with notebook_params. The JSON representation of this field (for example {'jar_params':['john doe','35']}) cannot exceed 10,000 bytes. Use Task parameter variables to set parameters containing information about job runs, e.g.

["john", "doe", "35"]
None
notebook_params Optional[Dict]

A map from keys to values for jobs with notebook task, for example 'notebook_params': {'name': 'john doe', 'age': '35'}. The map is passed to the notebook and is accessible through the dbutils.widgets.get function. If not specified upon run-now, the triggered run uses the job’s base parameters. notebook_params cannot be specified in conjunction with jar_params. Use Task parameter variables to set parameters containing information about job runs. The JSON representation of this field (for example {'notebook_params':{'name':'john doe','age':'35'}}) cannot exceed 10,000 bytes, e.g.

{"name": "john doe", "age": "35"}
None
python_params Optional[List[str]]

A list of parameters for jobs with Python tasks, for example 'python_params': ['john doe', '35']. The parameters are passed to Python file as command-line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The JSON representation of this field (for example {'python_params':['john doe','35']}) cannot exceed 10,000 bytes. Use Task parameter variables to set parameters containing information about job runs. Important These parameters accept only Latin characters (ASCII character set). Using non-ASCII characters returns an error. Examples of invalid, non-ASCII characters are Chinese, Japanese kanjis, and emojis, e.g.

["john doe", "35"]
None
spark_submit_params Optional[List[str]]

A list of parameters for jobs with spark submit task, for example 'spark_submit_params': ['--class', 'org.apache.spark.examples.SparkPi']. The parameters are passed to spark-submit script as command-line parameters. If specified upon run-now, it would overwrite the parameters specified in job setting. The JSON representation of this field (for example {'python_params':['john doe','35']}) cannot exceed 10,000 bytes. Use Task parameter variables to set parameters containing information about job runs. Important These parameters accept only Latin characters (ASCII character set). Using non-ASCII characters returns an error. Examples of invalid, non-ASCII characters are Chinese, Japanese kanjis, and emojis, e.g.

["--class", "org.apache.spark.examples.SparkPi"]
None
python_named_params Optional[Dict]

A map from keys to values for jobs with Python wheel task, for example 'python_named_params': {'name': 'task', 'data': 'dbfs:/path/to/data.json'}, e.g.

{"name": "task", "data": "dbfs:/path/to/data.json"}
None
pipeline_params Optional[str]
None
sql_params Optional[Dict]

A map from keys to values for SQL tasks, for example 'sql_params': {'name': 'john doe', 'age': '35'}. The SQL alert task does not support custom parameters, e.g.

{"name": "john doe", "age": "35"}
None
dbt_commands Optional[List]

An array of commands to execute for jobs with the dbt task, for example 'dbt_commands': ['dbt deps', 'dbt seed', 'dbt run'], e.g.

["dbt deps", "dbt seed", "dbt run"]
None
job_parameters Optional[Dict]

A map from keys to values for job-level parameters used in the run, for example 'job_parameters': {'param': 'overriding_val'}, e.g.

{"param": "overriding_val"}
None

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- repair_id: int

API Endpoint:

/2.1/jobs/runs/repair

API Responses:

Response Description
200 Run repair was initiated.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
@task
async def jobs_runs_repair(
    databricks_credentials: "DatabricksCredentials",
    run_id: Optional[int] = None,
    rerun_tasks: Optional[List[str]] = None,
    latest_repair_id: Optional[int] = None,
    rerun_all_failed_tasks: bool = False,
    jar_params: Optional[List[str]] = None,
    notebook_params: Optional[Dict] = None,
    python_params: Optional[List[str]] = None,
    spark_submit_params: Optional[List[str]] = None,
    python_named_params: Optional[Dict] = None,
    pipeline_params: Optional[str] = None,
    sql_params: Optional[Dict] = None,
    dbt_commands: Optional[List] = None,
    job_parameters: Optional[Dict] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Re-run one or more tasks. Tasks are re-run as part of the original job run, use
    the current job and task settings, and can be viewed in the history for the
    original job run.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        run_id:
            The job run ID of the run to repair. The run must not be in progress,
            e.g. `455644833`.
        rerun_tasks:
            The task keys of the task runs to repair, e.g.
            ```
            ["task0", "task1"]
            ```
        latest_repair_id:
            The ID of the latest repair. This parameter is not required when
            repairing a run for the first time, but must be provided on
            subsequent requests to repair the same run, e.g.
            `734650698524280`.
        rerun_all_failed_tasks:
            If true, repair all failed tasks. Only one of rerun_tasks or
            rerun_all_failed_tasks can be used.
        jar_params:
            A list of parameters for jobs with Spark JAR tasks, for example
            `'jar_params': ['john doe', '35']`. The parameters are used
            to invoke the main function of the main class specified in
            the Spark JAR task. If not specified upon `run-now`, it
            defaults to an empty list. jar_params cannot be specified in
            conjunction with notebook_params. The JSON representation of
            this field (for example `{'jar_params':['john doe','35']}`)
            cannot exceed 10,000 bytes.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs, e.g.
            ```
            ["john", "doe", "35"]
            ```
        notebook_params:
            A map from keys to values for jobs with notebook task, for example
            `'notebook_params': {'name': 'john doe', 'age': '35'}`. The
            map is passed to the notebook and is accessible through the
            [dbutils.widgets.get](https://docs.databricks.com/dev-
            tools/databricks-utils.html
            dbutils-widgets) function.  If not specified upon `run-now`,
            the triggered run uses the job’s base parameters.
            notebook_params cannot be specified in conjunction with
            jar_params.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs.  The JSON representation of this
            field (for example `{'notebook_params':{'name':'john
            doe','age':'35'}}`) cannot exceed 10,000 bytes, e.g.
            ```
            {"name": "john doe", "age": "35"}
            ```
        python_params:
            A list of parameters for jobs with Python tasks, for example
            `'python_params': ['john doe', '35']`. The parameters are
            passed to Python file as command-line parameters. If
            specified upon `run-now`, it would overwrite the parameters
            specified in job setting. The JSON representation of this
            field (for example `{'python_params':['john doe','35']}`)
            cannot exceed 10,000 bytes.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs.  Important  These parameters
            accept only Latin characters (ASCII character set). Using
            non-ASCII characters returns an error. Examples of invalid,
            non-ASCII characters are Chinese, Japanese kanjis, and
            emojis, e.g.
            ```
            ["john doe", "35"]
            ```
        spark_submit_params:
            A list of parameters for jobs with spark submit task, for example
            `'spark_submit_params': ['--class',
            'org.apache.spark.examples.SparkPi']`. The parameters are
            passed to spark-submit script as command-line parameters. If
            specified upon `run-now`, it would overwrite the parameters
            specified in job setting. The JSON representation of this
            field (for example `{'python_params':['john doe','35']}`)
            cannot exceed 10,000 bytes.  Use [Task parameter
            variables](https://docs.databricks.com/jobs.html
            parameter-variables) to set parameters containing
            information about job runs.  Important  These parameters
            accept only Latin characters (ASCII character set). Using
            non-ASCII characters returns an error. Examples of invalid,
            non-ASCII characters are Chinese, Japanese kanjis, and
            emojis, e.g.
            ```
            ["--class", "org.apache.spark.examples.SparkPi"]
            ```
        python_named_params:
            A map from keys to values for jobs with Python wheel task, for example
            `'python_named_params': {'name': 'task', 'data':
            'dbfs:/path/to/data.json'}`, e.g.
            ```
            {"name": "task", "data": "dbfs:/path/to/data.json"}
            ```
        pipeline_params:

        sql_params:
            A map from keys to values for SQL tasks, for example `'sql_params':
            {'name': 'john doe', 'age': '35'}`. The SQL alert task does
            not support custom parameters, e.g.
            ```
            {"name": "john doe", "age": "35"}
            ```
        dbt_commands:
            An array of commands to execute for jobs with the dbt task, for example
            `'dbt_commands': ['dbt deps', 'dbt seed', 'dbt run']`, e.g.
            ```
            ["dbt deps", "dbt seed", "dbt run"]
            ```

        job_parameters:
            A map from keys to values for job-level parameters used in the run, for example
             `'job_parameters': {'param': 'overriding_val'}`, e.g.
            ```
            {"param": "overriding_val"}
            ```

    Returns:
        Upon success, a dict of the response. </br>- `repair_id: int`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/repair`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run repair was initiated. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/repair"  # noqa

    responses = {
        200: "Run repair was initiated.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "run_id": run_id,
        "rerun_tasks": rerun_tasks,
        "latest_repair_id": latest_repair_id,
        "rerun_all_failed_tasks": rerun_all_failed_tasks,
        "jar_params": jar_params,
        "notebook_params": notebook_params,
        "python_params": python_params,
        "spark_submit_params": spark_submit_params,
        "python_named_params": python_named_params,
        "pipeline_params": pipeline_params,
        "sql_params": sql_params,
        "dbt_commands": dbt_commands,
        "job_parameters": job_parameters,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_runs_submit(databricks_credentials, tasks=None, run_name=None, webhook_notifications=None, git_source=None, timeout_seconds=None, idempotency_token=None, access_control_list=None) async

Submit a one-time run. This endpoint allows you to submit a workload directly without creating a job. Use the jobs/runs/get API to check the run state after the job is submitted.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
tasks Optional[List[RunSubmitTaskSettings]]

, e.g.

[
    {
        "task_key": "Sessionize",
        "description": "Extracts session data from events",
        "depends_on": [],
        "existing_cluster_id": "0923-164208-meows279",
        "spark_jar_task": {
            "main_class_name": "com.databricks.Sessionize",
            "parameters": ["--data", "dbfs:/path/to/data.json"],
        },
        "libraries": [{"jar": "dbfs:/mnt/databricks/Sessionize.jar"}],
        "timeout_seconds": 86400,
    },
    {
        "task_key": "Orders_Ingest",
        "description": "Ingests order data",
        "depends_on": [],
        "existing_cluster_id": "0923-164208-meows279",
        "spark_jar_task": {
            "main_class_name": "com.databricks.OrdersIngest",
            "parameters": ["--data", "dbfs:/path/to/order-data.json"],
        },
        "libraries": [{"jar": "dbfs:/mnt/databricks/OrderIngest.jar"}],
        "timeout_seconds": 86400,
    },
    {
        "task_key": "Match",
        "description": "Matches orders with user sessions",
        "depends_on": [
            {"task_key": "Orders_Ingest"},
            {"task_key": "Sessionize"},
        ],
        "new_cluster": {
            "spark_version": "7.3.x-scala2.12",
            "node_type_id": "i3.xlarge",
            "spark_conf": {"spark.speculation": True},
            "aws_attributes": {
                "availability": "SPOT",
                "zone_id": "us-west-2a",
            },
            "autoscale": {"min_workers": 2, "max_workers": 16},
        },
        "notebook_task": {
            "notebook_path": "/Users/user.name@databricks.com/Match",
            "source": "WORKSPACE",
            "base_parameters": {"name": "John Doe", "age": "35"},
        },
        "timeout_seconds": 86400,
    },
]
None
run_name Optional[str]

An optional name for the run. The default value is Untitled, e.g. A multitask job run.

None
webhook_notifications WebhookNotifications

A collection of system notification IDs to notify when runs of this job begin or complete. The default behavior is to not send any system notifications. Key-values: - on_start: An optional list of notification IDs to call when the run starts. A maximum of 3 destinations can be specified for the on_start property, e.g. [ {"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"}, {"id": "0481e838-0a59-4eff-9541-a4ca6f149574"}, ] - on_success: An optional list of notification IDs to call when the run completes successfully. A maximum of 3 destinations can be specified for the on_success property, e.g. [{"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"}] - on_failure: An optional list of notification IDs to call when the run fails. A maximum of 3 destinations can be specified for the on_failure property, e.g. [{"id": "0481e838-0a59-4eff-9541-a4ca6f149574"}]

None
git_source GitSource

This functionality is in Public Preview. An optional specification for a remote repository containing the notebooks used by this job's notebook tasks, e.g. { "git_url": "https://github.com/databricks/databricks-cli", "git_branch": "main", "git_provider": "gitHub", } Key-values: - git_url: URL of the repository to be cloned by this job. The maximum length is 300 characters, e.g. https://github.com/databricks/databricks-cli. - git_provider: Unique identifier of the service used to host the Git repository. The value is case insensitive, e.g. github. - git_branch: Name of the branch to be checked out and used by this job. This field cannot be specified in conjunction with git_tag or git_commit. The maximum length is 255 characters, e.g. main. - git_tag: Name of the tag to be checked out and used by this job. This field cannot be specified in conjunction with git_branch or git_commit. The maximum length is 255 characters, e.g. release-1.0.0. - git_commit: Commit to be checked out and used by this job. This field cannot be specified in conjunction with git_branch or git_tag. The maximum length is 64 characters, e.g. e0056d01. - git_snapshot: Read-only state of the remote repository at the time the job was run. This field is only included on job runs.

None
timeout_seconds Optional[int]

An optional timeout applied to each run of this job. The default behavior is to have no timeout, e.g. 86400.

None
idempotency_token Optional[str]

An optional token that can be used to guarantee the idempotency of job run requests. If a run with the provided token already exists, the request does not create a new run but returns the ID of the existing run instead. If a run with the provided token is deleted, an error is returned. If you specify the idempotency token, upon failure you can retry until the request succeeds. Databricks guarantees that exactly one run is launched with that idempotency token. This token must have at most 64 characters. For more information, see How to ensure idempotency for jobs, e.g. 8f018174-4792-40d5-bcbc-3e6a527352c8.

None
access_control_list Optional[List[AccessControlRequest]]

List of permissions to set on the job.

None

Returns:

Type Description
Dict[str, Any]

Upon success, a dict of the response.
- run_id: int

API Endpoint:

/2.1/jobs/runs/submit

API Responses:

Response Description
200 Run was created and started successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
@task
async def jobs_runs_submit(
    databricks_credentials: "DatabricksCredentials",
    tasks: Optional[List["models.RunSubmitTaskSettings"]] = None,
    run_name: Optional[str] = None,
    webhook_notifications: "models.WebhookNotifications" = None,
    git_source: "models.GitSource" = None,
    timeout_seconds: Optional[int] = None,
    idempotency_token: Optional[str] = None,
    access_control_list: Optional[List["models.AccessControlRequest"]] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Submit a one-time run. This endpoint allows you to submit a workload directly
    without creating a job. Use the `jobs/runs/get` API to check the run state
    after the job is submitted.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        tasks:
            , e.g.
            ```
            [
                {
                    "task_key": "Sessionize",
                    "description": "Extracts session data from events",
                    "depends_on": [],
                    "existing_cluster_id": "0923-164208-meows279",
                    "spark_jar_task": {
                        "main_class_name": "com.databricks.Sessionize",
                        "parameters": ["--data", "dbfs:/path/to/data.json"],
                    },
                    "libraries": [{"jar": "dbfs:/mnt/databricks/Sessionize.jar"}],
                    "timeout_seconds": 86400,
                },
                {
                    "task_key": "Orders_Ingest",
                    "description": "Ingests order data",
                    "depends_on": [],
                    "existing_cluster_id": "0923-164208-meows279",
                    "spark_jar_task": {
                        "main_class_name": "com.databricks.OrdersIngest",
                        "parameters": ["--data", "dbfs:/path/to/order-data.json"],
                    },
                    "libraries": [{"jar": "dbfs:/mnt/databricks/OrderIngest.jar"}],
                    "timeout_seconds": 86400,
                },
                {
                    "task_key": "Match",
                    "description": "Matches orders with user sessions",
                    "depends_on": [
                        {"task_key": "Orders_Ingest"},
                        {"task_key": "Sessionize"},
                    ],
                    "new_cluster": {
                        "spark_version": "7.3.x-scala2.12",
                        "node_type_id": "i3.xlarge",
                        "spark_conf": {"spark.speculation": True},
                        "aws_attributes": {
                            "availability": "SPOT",
                            "zone_id": "us-west-2a",
                        },
                        "autoscale": {"min_workers": 2, "max_workers": 16},
                    },
                    "notebook_task": {
                        "notebook_path": "/Users/user.name@databricks.com/Match",
                        "source": "WORKSPACE",
                        "base_parameters": {"name": "John Doe", "age": "35"},
                    },
                    "timeout_seconds": 86400,
                },
            ]
            ```
        run_name:
            An optional name for the run. The default value is `Untitled`, e.g. `A
            multitask job run`.
        webhook_notifications:
            A collection of system notification IDs to notify when runs of this job
            begin or complete. The default behavior is to not send any
            system notifications. Key-values:
            - on_start:
                An optional list of notification IDs to call when the run
                starts. A maximum of 3 destinations can be specified for the
                `on_start` property, e.g.
                ```
                [
                    {"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"},
                    {"id": "0481e838-0a59-4eff-9541-a4ca6f149574"},
                ]
                ```
            - on_success:
                An optional list of notification IDs to call when the run
                completes successfully. A maximum of 3 destinations can be
                specified for the `on_success` property, e.g.
                ```
                [{"id": "03dd86e4-57ef-4818-a950-78e41a1d71ab"}]
                ```
            - on_failure:
                An optional list of notification IDs to call when the run
                fails. A maximum of 3 destinations can be specified for the
                `on_failure` property, e.g.
                ```
                [{"id": "0481e838-0a59-4eff-9541-a4ca6f149574"}]
                ```
        git_source:
            This functionality is in Public Preview.  An optional specification for
            a remote repository containing the notebooks used by this
            job's notebook tasks, e.g.
            ```
            {
                "git_url": "https://github.com/databricks/databricks-cli",
                "git_branch": "main",
                "git_provider": "gitHub",
            }
            ``` Key-values:
            - git_url:
                URL of the repository to be cloned by this job. The maximum
                length is 300 characters, e.g.
                `https://github.com/databricks/databricks-cli`.
            - git_provider:
                Unique identifier of the service used to host the Git
                repository. The value is case insensitive, e.g. `github`.
            - git_branch:
                Name of the branch to be checked out and used by this job.
                This field cannot be specified in conjunction with git_tag
                or git_commit. The maximum length is 255 characters, e.g.
                `main`.
            - git_tag:
                Name of the tag to be checked out and used by this job. This
                field cannot be specified in conjunction with git_branch or
                git_commit. The maximum length is 255 characters, e.g.
                `release-1.0.0`.
            - git_commit:
                Commit to be checked out and used by this job. This field
                cannot be specified in conjunction with git_branch or
                git_tag. The maximum length is 64 characters, e.g.
                `e0056d01`.
            - git_snapshot:
                Read-only state of the remote repository at the time the job was run.
                            This field is only included on job runs.
        timeout_seconds:
            An optional timeout applied to each run of this job. The default
            behavior is to have no timeout, e.g. `86400`.
        idempotency_token:
            An optional token that can be used to guarantee the idempotency of job
            run requests. If a run with the provided token already
            exists, the request does not create a new run but returns
            the ID of the existing run instead. If a run with the
            provided token is deleted, an error is returned.  If you
            specify the idempotency token, upon failure you can retry
            until the request succeeds. Databricks guarantees that
            exactly one run is launched with that idempotency token.
            This token must have at most 64 characters.  For more
            information, see [How to ensure idempotency for
            jobs](https://kb.databricks.com/jobs/jobs-idempotency.html),
            e.g. `8f018174-4792-40d5-bcbc-3e6a527352c8`.
        access_control_list:
            List of permissions to set on the job.

    Returns:
        Upon success, a dict of the response. </br>- `run_id: int`</br>

    <h4>API Endpoint:</h4>
    `/2.1/jobs/runs/submit`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Run was created and started successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/runs/submit"  # noqa

    responses = {
        200: "Run was created and started successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "tasks": tasks,
        "run_name": run_name,
        "webhook_notifications": webhook_notifications,
        "git_source": git_source,
        "timeout_seconds": timeout_seconds,
        "idempotency_token": idempotency_token,
        "access_control_list": access_control_list,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents

jobs_update(databricks_credentials, job_id=None, new_settings=None, fields_to_remove=None) async

Add, update, or remove specific settings of an existing job. Use the Reset endpoint to overwrite all job settings.

Parameters:

Name Type Description Default
databricks_credentials DatabricksCredentials

Credentials to use for authentication with Databricks.

required
job_id Optional[int]

The canonical identifier of the job to update. This field is required, e.g. 11223344.

None
new_settings JobSettings

The new settings for the job. Any top-level fields specified in new_settings are completely replaced. Partially updating nested fields is not supported. Changes to the field JobSettings.timeout_seconds are applied to active runs. Changes to other fields are applied to future runs only. Key-values: - name: An optional name for the job, e.g. A multitask job. - tags: A map of tags associated with the job. These are forwarded to the cluster as cluster tags for jobs clusters, and are subject to the same limitations as cluster tags. A maximum of 25 tags can be added to the job, e.g. {"cost-center": "engineering", "team": "jobs"} - tasks: A list of task specifications to be executed by this job, e.g. [ { "task_key": "Sessionize", "description": "Extracts session data from events", "depends_on": [], "existing_cluster_id": "0923-164208-meows279", "spark_jar_task": { "main_class_name": "com.databricks.Sessionize", "parameters": [ "--data", "dbfs:/path/to/data.json", ], }, "libraries": [ {"jar": "dbfs:/mnt/databricks/Sessionize.jar"} ], "timeout_seconds": 86400, "max_retries": 3, "min_retry_interval_millis": 2000, "retry_on_timeout": False, }, { "task_key": "Orders_Ingest", "description": "Ingests order data", "depends_on": [], "job_cluster_key": "auto_scaling_cluster", "spark_jar_task": { "main_class_name": "com.databricks.OrdersIngest", "parameters": [ "--data", "dbfs:/path/to/order-data.json", ], }, "libraries": [ {"jar": "dbfs:/mnt/databricks/OrderIngest.jar"} ], "timeout_seconds": 86400, "max_retries": 3, "min_retry_interval_millis": 2000, "retry_on_timeout": False, }, { "task_key": "Match", "description": "Matches orders with user sessions", "depends_on": [ {"task_key": "Orders_Ingest"}, {"task_key": "Sessionize"}, ], "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "i3.xlarge", "spark_conf": {"spark.speculation": True}, "aws_attributes": { "availability": "SPOT", "zone_id": "us-west-2a", }, "autoscale": { "min_workers": 2, "max_workers": 16, }, }, "notebook_task": { "notebook_path": "/Users/user.name@databricks.com/Match", "source": "WORKSPACE", "base_parameters": { "name": "John Doe", "age": "35", }, }, "timeout_seconds": 86400, "max_retries": 3, "min_retry_interval_millis": 2000, "retry_on_timeout": False, }, ] - job_clusters: A list of job cluster specifications that can be shared and reused by tasks of this job. Libraries cannot be declared in a shared job cluster. You must declare dependent libraries in task settings, e.g. [ { "job_cluster_key": "auto_scaling_cluster", "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "i3.xlarge", "spark_conf": {"spark.speculation": True}, "aws_attributes": { "availability": "SPOT", "zone_id": "us-west-2a", }, "autoscale": { "min_workers": 2, "max_workers": 16, }, }, } ] - email_notifications: An optional set of email addresses that is notified when runs of this job begin or complete as well as when this job is deleted. The default behavior is to not send any emails. - webhook_notifications: A collection of system notification IDs to notify when runs of this job begin or complete. The default behavior is to not send any system notifications. - timeout_seconds: An optional timeout applied to each run of this job. The default behavior is to have no timeout, e.g. 86400. - schedule: An optional periodic schedule for this job. The default behavior is that the job only runs when triggered by clicking “Run Now” in the Jobs UI or sending an API request to runNow. - max_concurrent_runs: An optional maximum allowed number of concurrent runs of the job. Set this value if you want to be able to execute multiple runs of the same job concurrently. This is useful for example if you trigger your job on a frequent schedule and want to allow consecutive runs to overlap with each other, or if you want to trigger multiple runs which differ by their input parameters. This setting affects only new runs. For example, suppose the job’s concurrency is 4 and there are 4 concurrent active runs. Then setting the concurrency to 3 won’t kill any of the active runs. However, from then on, new runs are skipped unless there are fewer than 3 active runs. This value cannot exceed 1000. Setting this value to 0 causes all new runs to be skipped. The default behavior is to allow only 1 concurrent run, e.g. 10. - git_source: This functionality is in Public Preview. An optional specification for a remote repository containing the notebooks used by this job's notebook tasks, e.g. { "git_url": "https://github.com/databricks/databricks-cli", "git_branch": "main", "git_provider": "gitHub", } - format: Used to tell what is the format of the job. This field is ignored in Create/Update/Reset calls. When using the Jobs API 2.1 this value is always set to 'MULTI_TASK', e.g. MULTI_TASK. - parameters: Job-level parameter definitions.

None
fields_to_remove Optional[List[str]]

Remove top-level fields in the job settings. Removing nested fields is not supported. This field is optional, e.g.

["libraries", "schedule"]
None

Returns:

Type Description
Dict[str, Any]

Upon success, an empty dict.

API Endpoint:

/2.1/jobs/update

API Responses:

Response Description
200 Job was updated successfully.
400 The request was malformed. See JSON response for error details.
401 The request was unauthorized.
500 The request was not handled correctly due to a server error.
Source code in prefect_databricks/jobs.py
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
@task
async def jobs_update(
    databricks_credentials: "DatabricksCredentials",
    job_id: Optional[int] = None,
    new_settings: "models.JobSettings" = None,
    fields_to_remove: Optional[List[str]] = None,
) -> Dict[str, Any]:  # pragma: no cover
    """
    Add, update, or remove specific settings of an existing job. Use the Reset
    endpoint to overwrite all job settings.

    Args:
        databricks_credentials:
            Credentials to use for authentication with Databricks.
        job_id:
            The canonical identifier of the job to update. This field is required,
            e.g. `11223344`.
        new_settings:
            The new settings for the job. Any top-level fields specified in
            `new_settings` are completely replaced. Partially updating
            nested fields is not supported.  Changes to the field
            `JobSettings.timeout_seconds` are applied to active runs.
            Changes to other fields are applied to future runs only. Key-values:
            - name:
                An optional name for the job, e.g. `A multitask job`.
            - tags:
                A map of tags associated with the job. These are forwarded
                to the cluster as cluster tags for jobs clusters, and are
                subject to the same limitations as cluster tags. A maximum
                of 25 tags can be added to the job, e.g.
                ```
                {"cost-center": "engineering", "team": "jobs"}
                ```
            - tasks:
                A list of task specifications to be executed by this job, e.g.
                ```
                [
                    {
                        "task_key": "Sessionize",
                        "description": "Extracts session data from events",
                        "depends_on": [],
                        "existing_cluster_id": "0923-164208-meows279",
                        "spark_jar_task": {
                            "main_class_name": "com.databricks.Sessionize",
                            "parameters": [
                                "--data",
                                "dbfs:/path/to/data.json",
                            ],
                        },
                        "libraries": [
                            {"jar": "dbfs:/mnt/databricks/Sessionize.jar"}
                        ],
                        "timeout_seconds": 86400,
                        "max_retries": 3,
                        "min_retry_interval_millis": 2000,
                        "retry_on_timeout": False,
                    },
                    {
                        "task_key": "Orders_Ingest",
                        "description": "Ingests order data",
                        "depends_on": [],
                        "job_cluster_key": "auto_scaling_cluster",
                        "spark_jar_task": {
                            "main_class_name": "com.databricks.OrdersIngest",
                            "parameters": [
                                "--data",
                                "dbfs:/path/to/order-data.json",
                            ],
                        },
                        "libraries": [
                            {"jar": "dbfs:/mnt/databricks/OrderIngest.jar"}
                        ],
                        "timeout_seconds": 86400,
                        "max_retries": 3,
                        "min_retry_interval_millis": 2000,
                        "retry_on_timeout": False,
                    },
                    {
                        "task_key": "Match",
                        "description": "Matches orders with user sessions",
                        "depends_on": [
                            {"task_key": "Orders_Ingest"},
                            {"task_key": "Sessionize"},
                        ],
                        "new_cluster": {
                            "spark_version": "7.3.x-scala2.12",
                            "node_type_id": "i3.xlarge",
                            "spark_conf": {"spark.speculation": True},
                            "aws_attributes": {
                                "availability": "SPOT",
                                "zone_id": "us-west-2a",
                            },
                            "autoscale": {
                                "min_workers": 2,
                                "max_workers": 16,
                            },
                        },
                        "notebook_task": {
                            "notebook_path": "/Users/user.name@databricks.com/Match",
                            "source": "WORKSPACE",
                            "base_parameters": {
                                "name": "John Doe",
                                "age": "35",
                            },
                        },
                        "timeout_seconds": 86400,
                        "max_retries": 3,
                        "min_retry_interval_millis": 2000,
                        "retry_on_timeout": False,
                    },
                ]
                ```
            - job_clusters:
                A list of job cluster specifications that can be shared and
                reused by tasks of this job. Libraries cannot be declared in
                a shared job cluster. You must declare dependent libraries
                in task settings, e.g.
                ```
                [
                    {
                        "job_cluster_key": "auto_scaling_cluster",
                        "new_cluster": {
                            "spark_version": "7.3.x-scala2.12",
                            "node_type_id": "i3.xlarge",
                            "spark_conf": {"spark.speculation": True},
                            "aws_attributes": {
                                "availability": "SPOT",
                                "zone_id": "us-west-2a",
                            },
                            "autoscale": {
                                "min_workers": 2,
                                "max_workers": 16,
                            },
                        },
                    }
                ]
                ```
            - email_notifications:
                An optional set of email addresses that is notified when
                runs of this job begin or complete as well as when this job
                is deleted. The default behavior is to not send any emails.
            - webhook_notifications:
                A collection of system notification IDs to notify when runs
                of this job begin or complete. The default behavior is to
                not send any system notifications.
            - timeout_seconds:
                An optional timeout applied to each run of this job. The
                default behavior is to have no timeout, e.g. `86400`.
            - schedule:
                An optional periodic schedule for this job. The default
                behavior is that the job only runs when triggered by
                clicking “Run Now” in the Jobs UI or sending an API request
                to `runNow`.
            - max_concurrent_runs:
                An optional maximum allowed number of concurrent runs of the
                job.  Set this value if you want to be able to execute
                multiple runs of the same job concurrently. This is useful
                for example if you trigger your job on a frequent schedule
                and want to allow consecutive runs to overlap with each
                other, or if you want to trigger multiple runs which differ
                by their input parameters.  This setting affects only new
                runs. For example, suppose the job’s concurrency is 4 and
                there are 4 concurrent active runs. Then setting the
                concurrency to 3 won’t kill any of the active runs. However,
                from then on, new runs are skipped unless there are fewer
                than 3 active runs.  This value cannot exceed 1000\. Setting
                this value to 0 causes all new runs to be skipped. The
                default behavior is to allow only 1 concurrent run, e.g.
                `10`.
            - git_source:
                This functionality is in Public Preview.  An optional
                specification for a remote repository containing the
                notebooks used by this job's notebook tasks, e.g.
                ```
                {
                    "git_url": "https://github.com/databricks/databricks-cli",
                    "git_branch": "main",
                    "git_provider": "gitHub",
                }
                ```
            - format:
                Used to tell what is the format of the job. This field is
                ignored in Create/Update/Reset calls. When using the Jobs
                API 2.1 this value is always set to `'MULTI_TASK'`, e.g.
                `MULTI_TASK`.
            - parameters:
                Job-level parameter definitions.
        fields_to_remove:
            Remove top-level fields in the job settings. Removing nested fields is
            not supported. This field is optional, e.g.
            ```
            ["libraries", "schedule"]
            ```

    Returns:
        Upon success, an empty dict.

    <h4>API Endpoint:</h4>
    `/2.1/jobs/update`

    <h4>API Responses:</h4>
    | Response | Description |
    | --- | --- |
    | 200 | Job was updated successfully. |
    | 400 | The request was malformed. See JSON response for error details. |
    | 401 | The request was unauthorized. |
    | 500 | The request was not handled correctly due to a server error. |
    """  # noqa
    endpoint = "/2.1/jobs/update"  # noqa

    responses = {
        200: "Job was updated successfully.",  # noqa
        400: "The request was malformed. See JSON response for error details.",  # noqa
        401: "The request was unauthorized.",  # noqa
        500: "The request was not handled correctly due to a server error.",  # noqa
    }

    json_payload = {
        "job_id": job_id,
        "new_settings": new_settings,
        "fields_to_remove": fields_to_remove,
    }

    response = await execute_endpoint.fn(
        endpoint,
        databricks_credentials,
        http_method=HTTPMethod.POST,
        json=json_payload,
    )

    contents = _unpack_contents(response, responses)
    return contents