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

cron expression failed to be parsed - unknown unit "d" #517

Open
milahu opened this issue Feb 28, 2024 · 1 comment
Open

cron expression failed to be parsed - unknown unit "d" #517

milahu opened this issue Feb 28, 2024 · 1 comment

Comments

@milahu
Copy link

milahu commented Feb 28, 2024

would be nice to use @every 3d instead of @every 72h
or @every 2w instead of @every 336h

because days and weeks are easy to define, months and years are harder...

continue go-co-op/gocron#679

@ljluestc
Copy link

package main

import (
	"fmt"
	"github.com/go-co-op/gocron"
	"time"
)

func main() {
	// Create a new scheduler
	s := gocron.NewScheduler(time.UTC)

	// Schedule a job to run every 72 hours (3 days)
	s.Every(72).Hours().Do(func() {
		fmt.Println("Running task every 3 days!")
	})

	// Schedule a job to run every 336 hours (2 weeks)
	s.Every(336).Hours().Do(func() {
		fmt.Println("Running task every 2 weeks!")
	})

	// Start the scheduler
	s.StartAsync()

	// Keep the program running to allow scheduled jobs to execute
	select {}
}

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