Skip to content

Commit 55e0ea0

Browse files
committed
[core] Move acquireTimeout utility function to the callable package
1 parent 30669f1 commit 55e0ea0

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

core/integration/odc/plugin.go

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
178178
return
179179
}
180180

181-
timeout := acquireTimeout(ODC_CONFIGURE_TIMEOUT, varStack, "Configure", envId)
181+
timeout := callable.AcquireTimeout(ODC_CONFIGURE_TIMEOUT, varStack, "Configure", envId)
182182

183183
arguments := make(map[string]string)
184184
arguments["environment_id"] = envId
@@ -212,7 +212,7 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
212212
Warn("cannot acquire run number for ODC")
213213
}
214214

215-
timeout := acquireTimeout(ODC_START_TIMEOUT, varStack, "Start", envId)
215+
timeout := callable.AcquireTimeout(ODC_START_TIMEOUT, varStack, "Start", envId)
216216

217217
arguments := make(map[string]string)
218218
arguments["run_number"] = rn
@@ -234,7 +234,7 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
234234
return
235235
}
236236
stack["Stop"] = func() (out string) {
237-
timeout := acquireTimeout(ODC_STOP_TIMEOUT, varStack, "Stop", envId)
237+
timeout := callable.AcquireTimeout(ODC_STOP_TIMEOUT, varStack, "Stop", envId)
238238

239239
ctx, cancel := context.WithTimeout(context.Background(), timeout)
240240
defer cancel()
@@ -252,7 +252,7 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
252252
return
253253
}
254254
stack["Reset"] = func() (out string) {
255-
timeout := acquireTimeout(ODC_RESET_TIMEOUT, varStack, "Reset", envId)
255+
timeout := callable.AcquireTimeout(ODC_RESET_TIMEOUT, varStack, "Reset", envId)
256256

257257
ctx, cancel := context.WithTimeout(context.Background(), timeout)
258258
defer cancel()
@@ -270,7 +270,7 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
270270
return
271271
}
272272
stack["EnsureCleanup"] = func() (out string) {
273-
timeout := acquireTimeout(ODC_GENERAL_OP_TIMEOUT, varStack, "EnsureCleanup", envId)
273+
timeout := callable.AcquireTimeout(ODC_GENERAL_OP_TIMEOUT, varStack, "EnsureCleanup", envId)
274274

275275
ctx, cancel := context.WithTimeout(context.Background(), timeout)
276276
defer cancel()
@@ -295,26 +295,3 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
295295
func (p *Plugin) Destroy() error {
296296
return p.odcClient.Close()
297297
}
298-
299-
func acquireTimeout(defaultTimeout time.Duration, varStack map[string]string, callName string, envId string) time.Duration {
300-
timeout := defaultTimeout
301-
timeoutStr, ok := varStack["__call_timeout"] // the Call interface ensures we'll find this key
302-
// see Call.Call in callable/call.go for details
303-
if ok {
304-
var err error
305-
timeout, err = time.ParseDuration(timeoutStr)
306-
if err != nil {
307-
timeout = defaultTimeout
308-
log.WithField("partition", envId).
309-
WithField("call", callName).
310-
WithField("default", timeout.String()).
311-
Warn("could not parse timeout declaration for hook call")
312-
}
313-
} else {
314-
log.WithField("partition", envId).
315-
WithField("call", callName).
316-
WithField("default", timeout.String()).
317-
Warn("could not get timeout declaration for hook call")
318-
}
319-
return timeout
320-
}

core/workflow/callable/call.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,27 @@ type ParentRole interface {
188188
SendEvent(event.Event)
189189
SetRuntimeVar(key string, value string)
190190
GetCurrentRunNumber() uint32
191+
}
192+
193+
func AcquireTimeout(defaultTimeout time.Duration, varStack map[string]string, callName string, envId string) time.Duration {
194+
timeout := defaultTimeout
195+
timeoutStr, ok := varStack["__call_timeout"] // the Call interface ensures we'll find this key
196+
// see Call.Call in callable/call.go for details
197+
if ok {
198+
var err error
199+
timeout, err = time.ParseDuration(timeoutStr)
200+
if err != nil {
201+
timeout = defaultTimeout
202+
log.WithField("partition", envId).
203+
WithField("call", callName).
204+
WithField("default", timeout.String()).
205+
Warn("could not parse timeout declaration for hook call")
206+
}
207+
} else {
208+
log.WithField("partition", envId).
209+
WithField("call", callName).
210+
WithField("default", timeout.String()).
211+
Warn("could not get timeout declaration for hook call")
212+
}
213+
return timeout
191214
}

0 commit comments

Comments
 (0)