Skip to content

Commit

Permalink
Merge pull request #11 from yankeguo/feat-support-env-in-cron-expr
Browse files Browse the repository at this point in the history
feat support env in cron expr
  • Loading branch information
yankeguo authored Jan 19, 2024
2 parents 4ec9d41 + 8fbf567 commit 27cb85a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/munit/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func (ld *Loader) Load(opts LoadOptions) (output []Unit, skipped []Unit, err err
continue
}

// eval cron
if unit.Cron != "" {
unit.Cron = os.ExpandEnv(unit.Cron)
}

// replicas
if unit.Count > 1 {
for i := 0; i < unit.Count; i++ {
Expand Down
2 changes: 2 additions & 0 deletions pkg/munit/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
func TestNewLoader(t *testing.T) {
os.Setenv("MINIT_ENABLE", "@default")
os.Setenv("MINIT_DISABLE", "task-3,task-5")
os.Setenv("DEBUG_EVERY", "10s")
ld := NewLoader()
units, skipped, err := ld.Load(LoadOptions{
Dir: "testdata",
Expand All @@ -19,6 +20,7 @@ func TestNewLoader(t *testing.T) {
require.Len(t, units, 1)
require.Len(t, skipped, 4)
require.Equal(t, "task-4", units[0].Name)
require.Equal(t, "@every 10s", units[0].Cron)
}

func TestDupOrMakeMap(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/munit/testdata/test2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ command:
---
name: task-4
kind: cron
cron: "@every 10s"
cron: "@every ${DEBUG_EVERY}"
command:
- echo
- cron
Expand Down

0 comments on commit 27cb85a

Please sign in to comment.