diff options
author | Valery Piashchynski <[email protected]> | 2021-08-12 13:25:36 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-08-12 13:25:36 +0300 |
commit | ecbfc5c5265a9895f4e371ce4388f64df8714e63 (patch) | |
tree | df0749155487eae6bcdbb2456885131a21916f4d /plugins/jobs/drivers/ephemeral/item.go | |
parent | 4169e8374f581ba2213f8cd1833cc6b9b84438e8 (diff) |
Remove unneeded options, complete tests for the ephemeral, update proto
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/jobs/drivers/ephemeral/item.go')
-rw-r--r-- | plugins/jobs/drivers/ephemeral/item.go | 44 |
1 files changed, 11 insertions, 33 deletions
diff --git a/plugins/jobs/drivers/ephemeral/item.go b/plugins/jobs/drivers/ephemeral/item.go index 9fab8d24..1a61d7e9 100644 --- a/plugins/jobs/drivers/ephemeral/item.go +++ b/plugins/jobs/drivers/ephemeral/item.go @@ -1,6 +1,7 @@ package ephemeral import ( + "context" "time" json "github.com/json-iterator/go" @@ -37,11 +38,8 @@ type Options struct { // Delay defines time duration to delay execution for. Defaults to none. Delay int64 `json:"delay,omitempty"` - // Timeout defines for how broker should wait until treating job are failed. Defaults to 30 min. - Timeout int64 `json:"timeout,omitempty"` - // private - requeueCh chan *Item + requeueFn func(context.Context, *Item) error } // DelayDuration returns delay duration in a form of time.Duration. @@ -49,15 +47,6 @@ func (o *Options) DelayDuration() time.Duration { return time.Second * time.Duration(o.Delay) } -// TimeoutDuration returns timeout duration in a form of time.Duration. -func (o *Options) TimeoutDuration() time.Duration { - if o.Timeout == 0 { - return 30 * time.Minute - } - - return time.Second * time.Duration(o.Timeout) -} - func (i *Item) ID() string { return i.Ident } @@ -78,9 +67,8 @@ func (i *Item) Context() ([]byte, error) { ID string `json:"id"` Job string `json:"job"` Headers map[string][]string `json:"headers"` - Timeout int64 `json:"timeout"` Pipeline string `json:"pipeline"` - }{ID: i.Ident, Job: i.Job, Headers: i.Headers, Timeout: i.Options.Timeout, Pipeline: i.Options.Pipeline}, + }{ID: i.Ident, Job: i.Job, Headers: i.Headers, Pipeline: i.Options.Pipeline}, ) if err != nil { @@ -101,25 +89,16 @@ func (i *Item) Nack() error { } func (i *Item) Requeue(headers map[string][]string, delay int64) error { - go func() { - time.Sleep(time.Second * time.Duration(delay)) - // overwrite the delay - i.Options.Delay = delay - i.Headers = headers - select { - case i.Options.requeueCh <- i: - return - default: - // TODO(rustatian): logs? - return - } - }() + // overwrite the delay + i.Options.Delay = delay + i.Headers = headers - return nil -} + err := i.Options.requeueFn(context.Background(), i) + if err != nil { + return err + } -func (i *Item) Recycle() { - i.Options = nil + return nil } func fromJob(job *job.Job) *Item { @@ -131,7 +110,6 @@ func fromJob(job *job.Job) *Item { Priority: job.Options.Priority, Pipeline: job.Options.Pipeline, Delay: job.Options.Delay, - Timeout: job.Options.Timeout, }, } } |