Skip to content

Commit 7163e5e

Browse files
authored
Fix bind/unbind for Python support (#3063)
## Changes Support bind/unbind for resources declared in Python. It requires initializing the bundle before we allow selecting a resource to bind/unbind, because otherwise, Python resources are not yet loaded. ## Why Fixes #3019 ## Tests Add acceptance tests for bind/unbind of YAML and Python jobs.
1 parent 55b7e88 commit 7163e5e

File tree

21 files changed

+256
-14
lines changed

21 files changed

+256
-14
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bundle:
2+
name: my_project
3+
4+
resources:
5+
jobs:
6+
job_1:
7+
name: Updated Job
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
>>> [CLI] jobs create --json {"name": "My Job"}
3+
4+
>>> [CLI] bundle deployment bind job_1 [NUMID] --auto-approve
5+
Updating deployment state...
6+
Successfully bound job with an id '[NUMID]'. Run 'bundle deploy' to deploy changes to your workspace
7+
8+
>>> [CLI] bundle deploy
9+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_project/default/files...
10+
Deploying resources...
11+
Updating deployment state...
12+
Deployment complete!
13+
14+
>>> [CLI] jobs get [NUMID] --output json
15+
{
16+
"job_id":[NUMID],
17+
"settings": {
18+
"deployment": {
19+
"kind":"BUNDLE",
20+
"metadata_file_path":"/Workspace/Users/[USERNAME]/.bundle/my_project/default/state/metadata.json"
21+
},
22+
"edit_mode":"UI_LOCKED",
23+
"format":"MULTI_TASK",
24+
"max_concurrent_runs":1,
25+
"name":"Updated Job",
26+
"queue": {
27+
"enabled":true
28+
}
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
job_id=$(trace $CLI jobs create --json '{"name": "My Job"}' | jq -r '.job_id')
2+
3+
trace $CLI bundle deployment bind job_1 $job_id --auto-approve
4+
5+
trace $CLI bundle deploy
6+
7+
trace $CLI jobs get $job_id --output json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cloud = false # test leaves deployed job
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bundle:
2+
name: my_project
3+
4+
experimental:
5+
python:
6+
resources:
7+
- "resources:load_resources"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
>>> [CLI] jobs create --json {"name": "My Job"}
3+
4+
>>> uv run --with [DATABRICKS_BUNDLES_WHEEL] -q [CLI] bundle deployment bind job_1 [NUMID] --auto-approve
5+
Updating deployment state...
6+
Successfully bound job with an id '[NUMID]'. Run 'bundle deploy' to deploy changes to your workspace
7+
8+
>>> uv run --with [DATABRICKS_BUNDLES_WHEEL] -q [CLI] bundle deploy
9+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_project/default/files...
10+
Deploying resources...
11+
Updating deployment state...
12+
Deployment complete!
13+
14+
>>> [CLI] jobs get [NUMID] --output json
15+
{
16+
"job_id":[NUMID],
17+
"settings": {
18+
"deployment": {
19+
"kind":"BUNDLE",
20+
"metadata_file_path":"/Workspace/Users/[USERNAME]/.bundle/my_project/default/state/metadata.json"
21+
},
22+
"edit_mode":"UI_LOCKED",
23+
"format":"MULTI_TASK",
24+
"max_concurrent_runs":1,
25+
"name":"Updated Job",
26+
"queue": {
27+
"enabled":true
28+
}
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from databricks.bundles.core import Resources
2+
3+
4+
def load_resources() -> Resources:
5+
resources = Resources()
6+
7+
resources.add_job(
8+
resource_name="job_1",
9+
job={"name": "Updated Job"},
10+
)
11+
12+
return resources
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
UV_RUN="uv run --with $DATABRICKS_BUNDLES_WHEEL -q"
2+
3+
job_id=$(trace $CLI jobs create --json '{"name": "My Job"}' | jq -r '.job_id')
4+
5+
trace $UV_RUN $CLI bundle deployment bind job_1 $job_id --auto-approve
6+
7+
trace $UV_RUN $CLI bundle deploy
8+
9+
trace $CLI jobs get $job_id --output json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cloud = false # test leaves deployed job
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bundle:
2+
name: my_project
3+
4+
variables:
5+
job_name:
6+
description: "Job name"
7+
8+
resources:
9+
jobs:
10+
job_1:
11+
name: ${var.job_name}

0 commit comments

Comments
 (0)