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

performance wise question #507

Open
viseth opened this issue Oct 25, 2023 · 1 comment
Open

performance wise question #507

viseth opened this issue Oct 25, 2023 · 1 comment

Comments

@viseth
Copy link

viseth commented Oct 25, 2023

Hi,

Anyone has experienced issues or performance issue when running multiple cron ?

I wondering whether is it more efficient in terms of CPU, MEM consumption to initialize mulitple cron instead of a single one that will hold all variety of cron job.

var myCron1 = cron.New()
var myCron2 = cron.New()
var myCron3 = cron.New()
myCron1.Start()
myCron2.Start()
myCron3.Start()

I find it easier to have multiple cron to separated different type of jobs at a cost of code duplication.

Any insight ?

@ljluestc
Copy link

package main

import (
    "fmt"
    "github.com/robfig/cron/v3"
)

func main() {
    // Initialize a single cron instance
    c := cron.New()

    // Add multiple cron jobs
    c.AddFunc("0 0 * * *", func() { fmt.Println("Job 1: Daily midnight task") }) // Daily task
    c.AddFunc("*/5 * * * *", func() { fmt.Println("Job 2: Every 5 minutes task") }) // Every 5 minutes task
    c.AddFunc("0 0 1 * *", func() { fmt.Println("Job 3: Monthly task") }) // Monthly task

    // Start the cron instance
    c.Start()

    // Block the main thread to keep the cron jobs running
    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