Skip to content

Commit 4b21f81

Browse files
authored
Added notification_settings block to databricks_job resource (#2276)
The new configuration block allows to control handling of notifications for skipped & canceled runs for both email & webhook notifications. This fixes #2270
1 parent 3c2c2b5 commit 4b21f81

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

docs/resources/job.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ This block is used to specify Git repository information & branch/tag/commit tha
141141
* `on_start` - (Optional) (List) list of emails to notify when the run starts.
142142
* `on_success` - (Optional) (List) list of emails to notify when the run completes successfully.
143143
* `on_failure` - (Optional) (List) list of emails to notify when the run fails.
144-
* `no_alert_for_skipped_runs` - (Optional) (Bool) don't send alert for skipped runs.
144+
* `no_alert_for_skipped_runs` - (Optional) (Bool) don't send alert for skipped runs. (It's recommended to use the corresponding setting in the `notification_settings` configuration block).
145145

146146
### webhook_notifications Configuration Block
147147

@@ -169,6 +169,13 @@ webhook_notifications {
169169

170170
-> **Note** The following configuration blocks can be standalone or nested inside a `task` block
171171

172+
### notification_settings Configuration Block
173+
174+
This block controls notification settings for both email & webhook notifications:
175+
176+
* `no_alert_for_skipped_runs` - (Optional) (Bool) don't send alert for skipped runs.
177+
* `no_alert_for_canceled_runs` - (Optional) (Bool) don't send alert for cancelled runs.
178+
172179
### spark_jar_task Configuration Block
173180

174181
* `parameters` - (Optional) (List) Parameters passed to the main method.

jobs/resource_job.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ type WebhookNotifications struct {
114114
OnFailure []Webhook `json:"on_failure,omitempty"`
115115
}
116116

117+
// NotificationSettings control the notification settings for a job
118+
type NotificationSettings struct {
119+
NoAlertForSkippedRuns bool `json:"no_alert_for_skipped_runs,omitempty"`
120+
NoAlertForCanceledRuns bool `json:"no_alert_for_canceled_runs,omitempty"`
121+
}
122+
117123
func (wn *WebhookNotifications) Sort() {
118124
if wn == nil {
119125
return
@@ -242,6 +248,7 @@ type JobSettings struct {
242248
MaxConcurrentRuns int32 `json:"max_concurrent_runs,omitempty"`
243249
EmailNotifications *EmailNotifications `json:"email_notifications,omitempty" tf:"suppress_diff"`
244250
WebhookNotifications *WebhookNotifications `json:"webhook_notifications,omitempty" tf:"suppress_diff"`
251+
NotificationSettings *NotificationSettings `json:"notification_settings,omitempty"`
245252
Tags map[string]string `json:"tags,omitempty"`
246253
Queue *Queue `json:"queue,omitempty"`
247254
}

jobs/resource_job_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ func TestResourceJobCreateWithWebhooks(t *testing.T) {
570570
OnSuccess: []Webhook{{ID: "id2"}},
571571
OnFailure: []Webhook{{ID: "id3"}},
572572
},
573+
NotificationSettings: &NotificationSettings{
574+
NoAlertForSkippedRuns: true,
575+
NoAlertForCanceledRuns: true,
576+
},
573577
},
574578
Response: Job{
575579
JobID: 789,
@@ -597,6 +601,10 @@ func TestResourceJobCreateWithWebhooks(t *testing.T) {
597601
OnSuccess: []Webhook{{ID: "id2"}},
598602
OnFailure: []Webhook{{ID: "id3"}},
599603
},
604+
NotificationSettings: &NotificationSettings{
605+
NoAlertForSkippedRuns: true,
606+
NoAlertForCanceledRuns: true,
607+
},
600608
},
601609
},
602610
},
@@ -628,7 +636,12 @@ func TestResourceJobCreateWithWebhooks(t *testing.T) {
628636
on_failure {
629637
id = "id3"
630638
}
631-
}`,
639+
}
640+
notification_settings {
641+
no_alert_for_skipped_runs = true
642+
no_alert_for_canceled_runs = true
643+
}
644+
`,
632645
}.Apply(t)
633646
assert.NoError(t, err)
634647
assert.Equal(t, "789", d.Id())

0 commit comments

Comments
 (0)