Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-note:enhancement added attempt deadline to scheduler resource #1639

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions google-beta/resource_cloud_scheduler_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ Headers can be set when the job is created.`,
},
ExactlyOneOf: []string{"pubsub_target", "http_target", "app_engine_http_target"},
},
"attempt_deadline": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: emptyOrDefaultStringSuppress("180s"),
Description: `The deadline for job attempts. If the request handler does not respond by this deadline then the request is
cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure. The failed attempt can be viewed in
execution logs. Cloud Scheduler will retry the job according to the RetryConfig.
The allowed duration for this deadline is:
* For HTTP targets, between 15 seconds and 30 minutes.
* For App Engine HTTP targets, between 15 seconds and 24 hours.
A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"`,
Default: "180s",
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -440,6 +454,12 @@ func resourceCloudSchedulerJobCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("time_zone"); !isEmptyValue(reflect.ValueOf(timeZoneProp)) && (ok || !reflect.DeepEqual(v, timeZoneProp)) {
obj["timeZone"] = timeZoneProp
}
attemptDeadlineProp, err := expandCloudSchedulerJobAttemptDeadline(d.Get("attempt_deadline"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("attempt_deadline"); !isEmptyValue(reflect.ValueOf(attemptDeadlineProp)) && (ok || !reflect.DeepEqual(v, attemptDeadlineProp)) {
obj["attemptDeadline"] = attemptDeadlineProp
}
retryConfigProp, err := expandCloudSchedulerJobRetryConfig(d.Get("retry_config"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -533,6 +553,9 @@ func resourceCloudSchedulerJobRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("time_zone", flattenCloudSchedulerJobTimeZone(res["timeZone"], d)); err != nil {
return fmt.Errorf("Error reading Job: %s", err)
}
if err := d.Set("attempt_deadline", flattenCloudSchedulerJobAttemptDeadline(res["attemptDeadline"], d)); err != nil {
return fmt.Errorf("Error reading Job: %s", err)
}
if err := d.Set("retry_config", flattenCloudSchedulerJobRetryConfig(res["retryConfig"], d)); err != nil {
return fmt.Errorf("Error reading Job: %s", err)
}
Expand Down Expand Up @@ -614,6 +637,10 @@ func flattenCloudSchedulerJobTimeZone(v interface{}, d *schema.ResourceData) int
return v
}

func flattenCloudSchedulerJobAttemptDeadline(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenCloudSchedulerJobRetryConfig(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -895,6 +922,10 @@ func expandCloudSchedulerJobTimeZone(v interface{}, d TerraformResourceData, con
return v, nil
}

func expandCloudSchedulerJobAttemptDeadline(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandCloudSchedulerJobRetryConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
36 changes: 20 additions & 16 deletions google-beta/resource_cloud_scheduler_job_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ func TestAccCloudSchedulerJob_schedulerJobHttpExample(t *testing.T) {
func testAccCloudSchedulerJob_schedulerJobHttpExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_cloud_scheduler_job" "job" {
name = "test-job%{random_suffix}"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
name = "test-job%{random_suffix}"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
attempt_deadline = "320s"

http_target {
http_method = "POST"
Expand Down Expand Up @@ -138,10 +139,11 @@ func TestAccCloudSchedulerJob_schedulerJobAppEngineExample(t *testing.T) {
func testAccCloudSchedulerJob_schedulerJobAppEngineExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_cloud_scheduler_job" "job" {
name = "test-job%{random_suffix}"
schedule = "*/4 * * * *"
description = "test app engine job"
time_zone = "Europe/London"
name = "test-job%{random_suffix}"
schedule = "*/4 * * * *"
description = "test app engine job"
time_zone = "Europe/London"
attempt_deadline = "320s"

app_engine_http_target {
http_method = "POST"
Expand Down Expand Up @@ -191,10 +193,11 @@ data "google_compute_default_service_account" "default" {
}

resource "google_cloud_scheduler_job" "job" {
name = "test-job%{random_suffix}"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
name = "test-job%{random_suffix}"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
attempt_deadline = "320s"

http_target {
http_method = "GET"
Expand Down Expand Up @@ -239,10 +242,11 @@ data "google_compute_default_service_account" "default" {
}

resource "google_cloud_scheduler_job" "job" {
name = "test-job%{random_suffix}"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
name = "test-job%{random_suffix}"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
attempt_deadline = "320s"

http_target {
http_method = "GET"
Expand Down
46 changes: 30 additions & 16 deletions website/docs/r/cloud_scheduler_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ resource "google_cloud_scheduler_job" "job" {

```hcl
resource "google_cloud_scheduler_job" "job" {
name = "test-job"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
name = "test-job"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
attempt_deadline = "320s"

http_target {
http_method = "POST"
Expand All @@ -93,10 +94,11 @@ resource "google_cloud_scheduler_job" "job" {

```hcl
resource "google_cloud_scheduler_job" "job" {
name = "test-job"
schedule = "*/4 * * * *"
description = "test app engine job"
time_zone = "Europe/London"
name = "test-job"
schedule = "*/4 * * * *"
description = "test app engine job"
time_zone = "Europe/London"
attempt_deadline = "320s"

app_engine_http_target {
http_method = "POST"
Expand Down Expand Up @@ -124,10 +126,11 @@ data "google_compute_default_service_account" "default" {
}

resource "google_cloud_scheduler_job" "job" {
name = "test-job"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
name = "test-job"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
attempt_deadline = "320s"

http_target {
http_method = "GET"
Expand All @@ -152,10 +155,11 @@ data "google_compute_default_service_account" "default" {
}

resource "google_cloud_scheduler_job" "job" {
name = "test-job"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
name = "test-job"
description = "test http job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
attempt_deadline = "320s"

http_target {
http_method = "GET"
Expand Down Expand Up @@ -199,6 +203,16 @@ The following arguments are supported:
Specifies the time zone to be used in interpreting schedule.
The value of this field must be a time zone name from the tz database.

* `attempt_deadline` -
(Optional)
The deadline for job attempts. If the request handler does not respond by this deadline then the request is
cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure. The failed attempt can be viewed in
execution logs. Cloud Scheduler will retry the job according to the RetryConfig.
The allowed duration for this deadline is:
* For HTTP targets, between 15 seconds and 30 minutes.
* For App Engine HTTP targets, between 15 seconds and 24 hours.
A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"

* `retry_config` -
(Optional)
By default, if a job does not complete successfully,
Expand Down