func CronServ(ctx context.Context, config config.Config, ns *noti.NotificationService) { log.Ctx(ctx).Info("Starting cron") c := cron.New() if config.Notification.Enabled { if _, err := c.AddFunc(config.Notification.CronExpression, func() { e := Notify(ns) if e != nil { log.Ctx(ctx).Errorf("Notification failed: %v", e) } }); err != nil { log.Ctx(ctx).Errorf("Failed to add cron job: %v", err) } } c.Start() // Wait for context cancellation to gracefully stop the cron service <-ctx.Done() log.Ctx(ctx).Info("Shutting down cron") c.Stop() }
My cron expression is * * * * *
I am not able to find out why is it triggering Notify method twice every minute? Do I need to change the cron expression to */1 * * * *?
If I add the expression as 0 * * * * * it is failed to parse the expression and getting the below error
expected exactly 5 fields, found 6: [0 * * * * *]