Skip to content

Cron is running twice every tick for the below code snippet. I want it to run once for every tick #553

Description

@pitamganai

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 * * * * *]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions