From 5ba4e7499bc0245da12c044f6b2f0e96f8ca486e Mon Sep 17 00:00:00 2001 From: GUO YANKE Date: Fri, 19 Jan 2024 14:55:13 +0800 Subject: [PATCH] feat: add env support in cron expression, #9 --- pkg/mrunners/runner_cron.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/mrunners/runner_cron.go b/pkg/mrunners/runner_cron.go index 183fa73..42092af 100644 --- a/pkg/mrunners/runner_cron.go +++ b/pkg/mrunners/runner_cron.go @@ -2,6 +2,7 @@ package mrunners import ( "context" + "os" "github.com/robfig/cron/v3" "github.com/yankeguo/minit/pkg/munit" @@ -40,8 +41,11 @@ func (r *runnerCron) Do(ctx context.Context) { } } + expr := os.ExpandEnv(r.Unit.Cron) + cr := cron.New(cron.WithLogger(cron.PrintfLogger(r.Logger))) - _, err := cr.AddFunc(r.Unit.Cron, func() { + + _, err := cr.AddFunc(expr, func() { r.Print("triggered") if err := r.Exec.Execute(r.Unit.ExecuteOptions(r.Logger)); err != nil { r.Error("failed executing: " + err.Error())