Skip to content

Commit 8eb31cc

Browse files
authored
Check for running resources with --fail-on-active-runs before any mutative operation during deploy (#2743)
## Changes Check for running resources with `--fail-on-active-runs` before any mutative operation during deploy Fixes #2671 ## Why We should check for running resources and fail if there are any earlier before any mutative operations such as artifacts folder clean up happens ## Tests Added acceptance test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 97a0506 commit 8eb31cc

File tree

7 files changed

+66
-1
lines changed

7 files changed

+66
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
### CLI
1010

1111
### Bundles
12+
* Check for running resources with --fail-on-active-runs before any mutative operation during deploy ([#2743](https://github.com/databricks/cli/pull/2743))
1213

1314
### API Changes
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bundle:
2+
name: fail-on-active-runs
3+
4+
resources:
5+
jobs:
6+
my_job:
7+
name: My Job
8+
tasks:
9+
- task_key: my_notebook
10+
notebook_task:
11+
notebook_path: my_notebook.py
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Databricks notebook source
2+
1 + 1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/fail-on-active-runs/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> errcode [CLI] bundle deploy --fail-on-active-runs
9+
Error: job 1 is running
10+
11+
12+
Exit code: 1
13+
14+
=== Expecting only 1 delete request to artifact_path/.internal folder from the first deploy
15+
>>> jq -s .[] | select(.path=="/api/2.0/workspace/delete") | select(.body.path | test(".*/artifacts/.internal")) out.requests.txt
16+
{
17+
"method": "POST",
18+
"path": "/api/2.0/workspace/delete",
19+
"body": {
20+
"path": "/Workspace/Users/[USERNAME]/.bundle/fail-on-active-runs/default/artifacts/.internal",
21+
"recursive": true
22+
}
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# We deploy the bundle first to create a job
2+
trace $CLI bundle deploy
3+
4+
# We deploy the bundle again to check that the deploy is failing if the job is running
5+
trace errcode $CLI bundle deploy --fail-on-active-runs
6+
7+
title "Expecting only 1 delete request to artifact_path/.internal folder from the first deploy"
8+
trace jq -s '.[] | select(.path=="/api/2.0/workspace/delete") | select(.body.path | test(".*/artifacts/.internal"))' out.requests.txt
9+
10+
rm out.requests.txt
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
RecordRequests = true
2+
3+
[[Server]]
4+
Pattern = "GET /api/2.2/jobs/runs/list"
5+
Response.Body = '''
6+
{
7+
"next_page_token": null,
8+
"runs": [
9+
{
10+
"id": 1234567890,
11+
"job_id": 1234567890,
12+
"status": {
13+
"state": "RUNNING"
14+
}
15+
}
16+
]
17+
}
18+
'''

bundle/phases/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
192192
terraform.CheckDashboardsModifiedRemotely(),
193193
deploy.StatePull(),
194194
mutator.ValidateGitDetails(),
195+
terraform.CheckRunningResource(),
195196
artifacts.CleanUp(),
196197
// libraries.CheckForSameNameLibraries() needs to be run after we expand glob references so we
197198
// know what are the actual library paths.
@@ -209,7 +210,6 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
209210
permissions.ApplyWorkspaceRootPermissions(),
210211
terraform.Interpolate(),
211212
terraform.Write(),
212-
terraform.CheckRunningResource(),
213213
terraform.Plan(terraform.PlanGoal("deploy")),
214214
)
215215

0 commit comments

Comments
 (0)