forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
201 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
// time.Duration forces you to specify in millis, and does not support days | ||
// see https://stackoverflow.com/questions/48050945/how-to-unmarshal-json-into-durations | ||
type TTL time.Duration | ||
|
||
func (l TTL) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(time.Duration(l).String()) | ||
} | ||
|
||
func (l *TTL) UnmarshalJSON(b []byte) error { | ||
var v interface{} | ||
if err := json.Unmarshal(b, &v); err != nil { | ||
return err | ||
} | ||
switch value := v.(type) { | ||
case string: | ||
if value == "" { | ||
*l = 0 | ||
return nil | ||
} | ||
if strings.HasSuffix(value, "d") { | ||
hours, err := strconv.Atoi(strings.TrimSuffix(value, "d")) | ||
*l = TTL(time.Duration(hours) * 24 * time.Hour) | ||
return err | ||
} | ||
d, err := time.ParseDuration(value) | ||
if err != nil { | ||
return err | ||
} | ||
*l = TTL(d) | ||
return nil | ||
default: | ||
return errors.New("invalid TTL") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTTL(t *testing.T) { | ||
t.Run("Empty", func(t *testing.T) { | ||
ttl := TTL(-1) | ||
err := ttl.UnmarshalJSON([]byte(`""`)) | ||
if assert.NoError(t, err) { | ||
assert.Equal(t, TTL(0), ttl) | ||
} | ||
}) | ||
t.Run("1h", func(t *testing.T) { | ||
ttl := TTL(-1) | ||
err := ttl.UnmarshalJSON([]byte(`"1h"`)) | ||
if assert.NoError(t, err) { | ||
assert.Equal(t, TTL(1*time.Hour), ttl) | ||
} | ||
}) | ||
t.Run("1d", func(t *testing.T) { | ||
ttl := TTL(-1) | ||
err := ttl.UnmarshalJSON([]byte(`"1d"`)) | ||
if assert.NoError(t, err) { | ||
assert.Equal(t, TTL(24*time.Hour), ttl) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ spec: | |
value: 30s | ||
- name: UPPERIO_DB_DEBUG | ||
value: "1" | ||
- name: ARCHIVED_WORKFLOW_GC_PERIOD | ||
value: 30s |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.