diff --git a/internal/cron/config.go b/internal/cron/config.go index 069724a..394df41 100644 --- a/internal/cron/config.go +++ b/internal/cron/config.go @@ -4,14 +4,12 @@ import ( "github.com/go-pg/pg/v10" "github.com/go-redis/redis/v8" "github.com/pkg/errors" - "github.com/robfig/cron/v3" ) type Config struct { DB *pg.DB Redis redis.UniversalClient RunOnInit bool - Opts []cron.Option WorkerLimit int } diff --git a/internal/cron/cron.go b/internal/cron/cron.go index 6ee17d8..d1beb51 100644 --- a/internal/cron/cron.go +++ b/internal/cron/cron.go @@ -30,12 +30,17 @@ func New(cfg *Config) (*Cron, error) { if err != nil { return nil, err } + log := logrus.WithField("package", "internal/cron") c := &Cron{ - Cron: cron.New(cfg.Opts...), + Cron: cron.New(cron.WithChain( + cron.SkipIfStillRunning( + cron.PrintfLogger(log), + ), + )), queue: q, db: cfg.DB, runOnInit: cfg.RunOnInit, - log: logrus.WithField("package", "internal/cron"), + log: log, } if err := c.init(); err != nil { return nil, err diff --git a/main.go b/main.go index 1a5016f..9abe8b7 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,6 @@ import ( "github.com/tribalwarshelp/cron/internal/postgres" "github.com/joho/godotenv" - "github.com/robfig/cron/v3" ) func init() { @@ -53,13 +52,6 @@ func main() { RunOnInit: envutil.GetenvBool("RUN_ON_INIT"), Redis: redisClient, WorkerLimit: envutil.GetenvInt("WORKER_LIMIT"), - Opts: []cron.Option{ - cron.WithChain( - cron.SkipIfStillRunning( - cron.PrintfLogger(logrus.WithField("package", "cron")), - ), - ), - }, }) if err != nil { logrus.Fatal(err)