Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/job.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ This block describes individual tasks:
* `disable_auto_optimization` - (Optional) A flag to disable auto optimization in serverless tasks.
* `email_notifications` - (Optional) An optional block to specify a set of email addresses notified when this task begins, completes or fails. The default behavior is to not send any emails. This block is [documented below](#email_notifications-configuration-block).
* `environment_key` - (Optional) identifier of an `environment` block that is used to specify libraries. Required for some tasks (`spark_python_task`, `python_wheel_task`, ...) running on serverless compute.
* `disabled` - (Optional) (Bool) An optional flag to disable the task. If set to `true`, the task will not run even if it is part of a job.
* `existing_cluster_id` - (Optional) Identifier of the [interactive cluster](cluster.md) to run job on. *Note: running tasks on interactive clusters may lead to increased costs!*
* `health` - (Optional) block described below that specifies health conditions for a given task.
* `job_cluster_key` - (Optional) Identifier of the Job cluster specified in the `job_cluster` block.
Expand Down
81 changes: 81 additions & 0 deletions jobs/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,87 @@ func TestAccJobTasks(t *testing.T) {
})
}

func TestAccJobDisabledTask(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the integration test locally and it failed with

expected task 'b' to have Disabled=true

From the logs, I don't see disabled as true in the API response, is this expected?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the integration test from this PR as the field is not yet working in every single environment.
Integration test was moved to another PR: #5506

acceptance.WorkspaceLevel(t, acceptance.Step{
Template: `
data "databricks_current_user" "me" {}
data "databricks_spark_version" "latest" {}
data "databricks_node_type" "smallest" {
local_disk = true
}

resource "databricks_notebook" "this" {
path = "${data.databricks_current_user.me.home}/Terraform{var.RANDOM}"
language = "PYTHON"
content_base64 = base64encode(<<-EOT
# created from ${abspath(path.module)}
display(spark.range(10))
EOT
)
}

resource "databricks_job" "this" {
name = "{var.RANDOM}"

task {
task_key = "a"

new_cluster {
num_workers = 1
spark_version = data.databricks_spark_version.latest.id
node_type_id = data.databricks_node_type.smallest.id
}

notebook_task {
notebook_path = databricks_notebook.this.path
}
}

task {
task_key = "b"
disabled = true

depends_on {
task_key = "a"
}

new_cluster {
num_workers = 1
spark_version = data.databricks_spark_version.latest.id
node_type_id = data.databricks_node_type.smallest.id
}

notebook_task {
notebook_path = databricks_notebook.this.path
}
}
}`,
Check: acceptance.ResourceCheck("databricks_job.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
w, err := client.WorkspaceClient()
assert.NoError(t, err)

jobID, err := strconv.ParseInt(id, 10, 64)
assert.NoError(t, err)

res, err := w.Jobs.Get(ctx, jobs.GetJobRequest{
JobId: jobID,
})
assert.NoError(t, err)

for _, task := range res.Settings.Tasks {
if task.TaskKey == "b" {
assert.True(t, task.Disabled, "expected task 'b' to have Disabled=true")
}
if task.TaskKey == "a" {
assert.False(t, task.Disabled, "expected task 'a' to have Disabled=false")
}
}

return nil
}),
})
}

func TestAccForEachTask(t *testing.T) {
t.Skip("Skipping this test because feature not enabled in Prod")
acceptance.WorkspaceLevel(t, acceptance.Step{
Expand Down
1 change: 1 addition & 0 deletions jobs/resource_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ type JobHealth struct {
type JobTaskSettings struct {
TaskKey string `json:"task_key"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
DependsOn []jobs.TaskDependency `json:"depends_on,omitempty"`
RunIf string `json:"run_if,omitempty"`

Expand Down
91 changes: 91 additions & 0 deletions jobs/resource_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,97 @@ func TestResourceJobCreate_MultiTask(t *testing.T) {
assert.Equal(t, "789", d.Id())
}

func TestResourceJobCreate_DisabledTask(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "POST",
Resource: "/api/2.2/jobs/create",
ExpectedRequest: JobSettings{
Name: "DisabledTaskJob",
Tasks: []JobTaskSettings{
{
TaskKey: "disabled_task",
Disabled: true,
ExistingClusterID: "abc",
DependsOn: []jobs.TaskDependency{
{
TaskKey: "enabled_task",
},
},
NotebookTask: &NotebookTask{
NotebookPath: "/Inactive",
},
},
{
TaskKey: "enabled_task",
ExistingClusterID: "abc",
NotebookTask: &NotebookTask{
NotebookPath: "/Active",
},
},
},
Queue: &jobs.QueueSettings{
Enabled: false,
},
MaxConcurrentRuns: 1,
},
Response: Job{
JobID: 123,
},
},
{
Method: "GET",
Resource: "/api/2.2/jobs/get?job_id=123",
Response: Job{
Settings: &JobSettings{
Tasks: []JobTaskSettings{
{
TaskKey: "enabled_task",
},
{
TaskKey: "disabled_task",
Disabled: true,
},
},
},
},
},
},
Create: true,
Resource: ResourceJob(),
HCL: `
name = "DisabledTaskJob"

task {
task_key = "enabled_task"

existing_cluster_id = "abc"

notebook_task {
notebook_path = "/Active"
}
}

task {
task_key = "disabled_task"
disabled = true

depends_on {
task_key = "enabled_task"
}

existing_cluster_id = "abc"

notebook_task {
notebook_path = "/Inactive"
}
}`,
}.Apply(t)
assert.NoError(t, err)
assert.Equal(t, "123", d.Id())
}

func TestResourceJobCreate_TaskOrder(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down
Loading