Skip to content

Commit

Permalink
feat: add env support in cron expression, #9
Browse files Browse the repository at this point in the history
  • Loading branch information
yankeguo committed Jan 19, 2024
1 parent 4ec9d41 commit 5ba4e74
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/mrunners/runner_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mrunners

import (
"context"
"os"

"github.com/robfig/cron/v3"
"github.com/yankeguo/minit/pkg/munit"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 5ba4e74

Please sign in to comment.