Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing cron schedule on Linux/arm64 #528

Open
ignazio-ingenito opened this issue Sep 4, 2024 · 1 comment
Open

Error parsing cron schedule on Linux/arm64 #528

ignazio-ingenito opened this issue Sep 4, 2024 · 1 comment

Comments

@ignazio-ingenito
Copy link

I got this error on Docker using linux/arm64, on linux/amd64 everything is working fine

Cron schedule: "* * * * *"
2024/09/04 04:15:34 failed to parse int from "*: strconv.Atoi: parsing "\"*": invalid syntax
panic: failed to parse int from "*: strconv.Atoi: parsing "\"*": invalid syntax

Try to do

func Setup(f func()) (*cron.Cron, error) {
	// Set the timezone
	loc, err := time.LoadLocation("Europe/Rome")
	if err != nil {
		log.Panicln(err)
	}

	// Set the cron schedule
	schedule := os.Getenv("APP_CRON_SCHEDULE")
	if schedule == "" {
		schedule = "0 */4 * * *"
	}
	fmt.Println("Cron schedule: " + schedule)

	// Create the cronjob
	token := strings.Split(schedule, " ")
	c := &cron.Cron{}
	if len(token) == 6 {
		c = cron.New(cron.WithSeconds(), cron.WithLocation(loc))
	} else {
		c = cron.New(cron.WithLocation(loc))
	}
	// Add a job to the cron
	id, err := c.AddFunc(schedule, f)
	if err != nil {
		log.Panicln(err)
	}
	log.Printf("Cron id: %d\n", id)

	// Start the cron
	c.Start()
	return c, nil
}
@norman-abramovitz
Copy link

I suspect your docker image does not have the latest cron library as you said a linux/arm64 works just fine. This library does not seem to be maintained anymore given the simple go maintenance items it requires, outstanding issues and outstanding prs that it has.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants