From f9b6dd2022eedf5aa7913f2dbb3ef19d454607bb Mon Sep 17 00:00:00 2001 From: Oliver Borchert Date: Tue, 23 Aug 2022 23:08:06 +0200 Subject: [PATCH 1/2] Add retry delay option --- rundeck/job.go | 1 + rundeck/resource_job.go | 9 +++++++++ website/docs/r/job.html.md | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/rundeck/job.go b/rundeck/job.go index 33238babf..715fa277a 100644 --- a/rundeck/job.go +++ b/rundeck/job.go @@ -69,6 +69,7 @@ type JobDetail struct { Notification *JobNotification `xml:"notification,omitempty"` Timeout string `xml:"timeout,omitempty"` Retry string `xml:"retry,omitempty"` + RetryDelay string `xml:"retry_delay,omitempty"` NodeFilter *JobNodeFilter `xml:"nodefilters,omitempty"` /* If Dispatch is enabled, nodesSelectedByDefault is always present with true/false. diff --git a/rundeck/resource_job.go b/rundeck/resource_job.go index 99679a44d..83b162e33 100644 --- a/rundeck/resource_job.go +++ b/rundeck/resource_job.go @@ -62,6 +62,11 @@ func resourceRundeckJob() *schema.Resource { Optional: true, }, + "retry_delay": { + Type: schema.TypeString, + Optional: true, + }, + "max_thread_count": { Type: schema.TypeInt, Optional: true, @@ -596,6 +601,7 @@ func jobFromResourceData(d *schema.ResourceData) (*JobDetail, error) { LogLevel: d.Get("log_level").(string), AllowConcurrentExecutions: d.Get("allow_concurrent_executions").(bool), Retry: d.Get("retry").(string), + RetryDelay: d.Get("retry_delay").(string), Dispatch: &JobDispatch{ MaxThreadCount: d.Get("max_thread_count").(int), ContinueNextNodeOnError: d.Get("continue_next_node_on_error").(bool), @@ -820,6 +826,9 @@ func jobToResourceData(job *JobDetail, d *schema.ResourceData) error { if err := d.Set("retry", job.Retry); err != nil { return err } + if err := d.Set("retry_delay", job.RetryDelay); err != nil { + return err + } if job.Dispatch != nil { if err := d.Set("max_thread_count", job.Dispatch.MaxThreadCount); err != nil { diff --git a/website/docs/r/job.html.md b/website/docs/r/job.html.md index 10ffe86bd..c3d04e2bf 100644 --- a/website/docs/r/job.html.md +++ b/website/docs/r/job.html.md @@ -70,6 +70,10 @@ The following arguments are supported: value reference like "${option.retry}". The default is `0`, meaning that jobs will only run once. +* `retry_delay` - (Optional) The time between the failed execution and the retry. Time in seconds or + specify time units: "120m", "2h", "3d". Use 0 to indicate no delay. Can include option value + references like "${option.delay}". The default is 0. + * `max_thread_count` - (Optional) The maximum number of threads to use to execute this job, which controls on how many nodes the commands can be run simulateneously. Defaults to 1, meaning that the nodes will be visited sequentially. From b2b562aec2953bb536bf30630c2e9d889e1a4aea Mon Sep 17 00:00:00 2001 From: Oliver Borchert Date: Tue, 13 Sep 2022 18:29:04 +0200 Subject: [PATCH 2/2] Parse retry delay as XML attribute --- rundeck/job.go | 8 ++++++-- rundeck/resource_job.go | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/rundeck/job.go b/rundeck/job.go index 715fa277a..722de88fc 100644 --- a/rundeck/job.go +++ b/rundeck/job.go @@ -68,8 +68,7 @@ type JobDetail struct { CommandSequence *JobCommandSequence `xml:"sequence,omitempty"` Notification *JobNotification `xml:"notification,omitempty"` Timeout string `xml:"timeout,omitempty"` - Retry string `xml:"retry,omitempty"` - RetryDelay string `xml:"retry_delay,omitempty"` + Retry *Retry `xml:"retry,omitempty"` NodeFilter *JobNodeFilter `xml:"nodefilters,omitempty"` /* If Dispatch is enabled, nodesSelectedByDefault is always present with true/false. @@ -86,6 +85,11 @@ type Boolean struct { Value bool `xml:",chardata"` } +type Retry struct { + Delay string `xml:"delay,attr"` + Value string `xml:",chardata"` +} + type JobNotification struct { OnFailure *Notification `xml:"onfailure,omitempty"` OnStart *Notification `xml:"onstart,omitempty"` diff --git a/rundeck/resource_job.go b/rundeck/resource_job.go index 83b162e33..7e46880bf 100644 --- a/rundeck/resource_job.go +++ b/rundeck/resource_job.go @@ -600,8 +600,10 @@ func jobFromResourceData(d *schema.ResourceData) (*JobDetail, error) { TimeZone: d.Get("time_zone").(string), LogLevel: d.Get("log_level").(string), AllowConcurrentExecutions: d.Get("allow_concurrent_executions").(bool), - Retry: d.Get("retry").(string), - RetryDelay: d.Get("retry_delay").(string), + Retry: &Retry{ + Value: d.Get("retry").(string), + Delay: d.Get("retry_delay").(string), + }, Dispatch: &JobDispatch{ MaxThreadCount: d.Get("max_thread_count").(int), ContinueNextNodeOnError: d.Get("continue_next_node_on_error").(bool), @@ -823,13 +825,14 @@ func jobToResourceData(job *JobDetail, d *schema.ResourceData) error { if err := d.Set("allow_concurrent_executions", job.AllowConcurrentExecutions); err != nil { return err } - if err := d.Set("retry", job.Retry); err != nil { - return err - } - if err := d.Set("retry_delay", job.RetryDelay); err != nil { - return err + if job.Retry != nil { + if err := d.Set("retry", job.Retry.Value); err != nil { + return err + } + if err := d.Set("retry_delay", job.Retry.Delay); err != nil { + return err + } } - if job.Dispatch != nil { if err := d.Set("max_thread_count", job.Dispatch.MaxThreadCount); err != nil { return err