Skip to content

Commit 127ca04

Browse files
authored
refactor: remove the default timeout for executables (#239)
1 parent 7734e7a commit 127ca04

File tree

10 files changed

+16
-19
lines changed

10 files changed

+16
-19
lines changed

docs/schemas/flowfile_schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
},
7777
"timeout": {
7878
"description": "The maximum amount of time the executable is allowed to run before being terminated.\nThe timeout is specified in Go duration format (e.g. 30s, 5m, 1h).\n",
79-
"type": "string",
80-
"default": "30m0s"
79+
"type": "string"
8180
},
8281
"verb": {
8382
"$ref": "#/definitions/ExecutableVerb",

docs/types/flowfile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Executables are the building blocks of workflows and are used to define the acti
9090
| `request` | | [ExecutableRequestExecutableType](#ExecutableRequestExecutableType) | <no value> | |
9191
| `serial` | | [ExecutableSerialExecutableType](#ExecutableSerialExecutableType) | <no value> | |
9292
| `tags` | | [CommonTags](#CommonTags) | [] | |
93-
| `timeout` | The maximum amount of time the executable is allowed to run before being terminated. The timeout is specified in Go duration format (e.g. 30s, 5m, 1h). | `string` | 30m0s | |
93+
| `timeout` | The maximum amount of time the executable is allowed to run before being terminated. The timeout is specified in Go duration format (e.g. 30s, 5m, 1h). | `string` | <no value> | |
9494
| `verb` | | [ExecutableVerb](#ExecutableVerb) | exec ||
9595
| `visibility` | | [CommonVisibility](#CommonVisibility) | <no value> | |
9696

internal/cache/executable_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func executablesFromFile(logger io.Logger, fileBase, filePath string) (*executab
5858
if err != nil {
5959
return nil, errors.Wrapf(err, "unable to parse timeout duration %s", value)
6060
}
61-
exec.Timeout = dur
61+
exec.Timeout = &dur
6262
case fileparser.VerbConfigurationKey:
6363
exec.Verb = executable.Verb(value)
6464
case fileparser.NameConfigurationKey:

internal/runner/runner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func Exec(
4343
return fmt.Errorf("compatible runner not found for executable %s", executable.ID())
4444
}
4545

46-
if executable.Timeout == 0 {
46+
if executable.Timeout == nil {
4747
return assignedRunner.Exec(ctx, executable, eng, inputEnv)
4848
}
4949

@@ -55,8 +55,8 @@ func Exec(
5555
select {
5656
case err := <-done:
5757
return err
58-
case <-time.After(executable.Timeout):
59-
return fmt.Errorf("timeout after %v", executable.Timeout)
58+
case <-time.After(*executable.Timeout):
59+
return fmt.Errorf("timeout after %v", *executable.Timeout)
6060
}
6161
}
6262

internal/runner/runner_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ var _ = Describe("Runner", func() {
6969

7070
It("should return error when execution times out", func() {
7171
ctx := &context.Context{}
72+
timeout := 250 * time.Millisecond
7273
exec := &executable.Executable{
7374
Name: "test-exec",
74-
Timeout: 250 * time.Millisecond,
75+
Timeout: &timeout,
7576
}
7677
promptedEnv := make(map[string]string)
7778

tools/builder/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func ExecWithTimeout(opts ...Option) *executable.Executable {
9191
Name: name,
9292
Visibility: privateExecVisibility(),
9393
Description: docstring,
94-
Timeout: timeout,
94+
Timeout: &timeout,
9595
Exec: &executable.ExecExecutableType{
9696
Cmd: fmt.Sprintf("sleep %d", int(timeout.Seconds()+10)),
9797
},

types/executable/executable.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/executable/executable.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import (
2121
//go:generate go run github.com/atombender/[email protected] -et --only-models -p executable -o executable.gen.go --capitalization URI --capitalization URL executable_schema.yaml
2222

2323
const (
24-
TmpDirLabel = "f:tmp"
25-
DefaultTimeout = 30 * time.Minute
24+
TmpDirLabel = "f:tmp"
2625
)
2726

2827
type ExecutableList []*Executable
@@ -231,11 +230,10 @@ func (e *Executable) SetDefaults() {
231230
e.Visibility = &v
232231
}
233232

234-
if e.Timeout == 0 {
235-
e.Timeout = DefaultTimeout
233+
if e.Timeout == nil {
236234
if v, ok := os.LookupEnv(TimeoutOverrideEnv); ok {
237235
if d, err := time.ParseDuration(v); err == nil {
238-
e.Timeout = d
236+
e.Timeout = &d
239237
}
240238
}
241239
}
@@ -540,7 +538,7 @@ func (e *Executable) MarshalJSON() ([]byte, error) {
540538
}{
541539
Alias: (*Alias)(e),
542540
}
543-
if e.Timeout != 0 {
541+
if e.Timeout != nil {
544542
aux.Timeout = e.Timeout.String()
545543
}
546544
return json.Marshal(aux)
@@ -562,7 +560,7 @@ func (e *Executable) UnmarshalJSON(data []byte) error {
562560
if err != nil {
563561
return err
564562
}
565-
e.Timeout = duration
563+
e.Timeout = &duration
566564
}
567565
return nil
568566
}

types/executable/executable_md.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func execMarkdown(e *Executable) string {
1414
if e.Visibility != nil {
1515
mkdwn += fmt.Sprintf("**Visibility:** %s\n", *e.Visibility)
1616
}
17-
if e.Timeout != 0 {
17+
if e.Timeout != nil {
1818
mkdwn += fmt.Sprintf("**Timeout:** %s\n", e.Timeout.String())
1919
}
2020
if len(e.Aliases) > 0 {

types/executable/executable_schema.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,6 @@ properties:
624624
description: |
625625
The maximum amount of time the executable is allowed to run before being terminated.
626626
The timeout is specified in Go duration format (e.g. 30s, 5m, 1h).
627-
default: 30m0s
628627
#### Executable context fields
629628
workspace:
630629
type: string

0 commit comments

Comments
 (0)