add initial application structure with configuration, logging, and health check endpoints
This commit is contained in:
39
internal/infra/cron/cron.go
Normal file
39
internal/infra/cron/cron.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package cron
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
"go.uber.org/fx"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"epic-ent/internal/config"
|
||||
)
|
||||
|
||||
func RegisterJobs(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) {
|
||||
if !cfg.Cron.Enabled {
|
||||
return
|
||||
}
|
||||
|
||||
loc, err := time.LoadLocation(cfg.Cron.Timezone)
|
||||
if err != nil {
|
||||
logger.Warn("invalid timezone, fallback to Local", zap.Error(err))
|
||||
loc = time.Local
|
||||
}
|
||||
|
||||
c := cron.New(cron.WithLocation(loc))
|
||||
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
c.Start()
|
||||
logger.Info("cron started")
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
c.Stop()
|
||||
logger.Info("cron stopped")
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user