Last active
November 16, 2023 20:06
-
-
Save aashish-chaubey/45e538959f92d8cc71327d44511cf7f7 to your computer and use it in GitHub Desktop.
Revisions
-
aashish-chaubey revised this gist
Nov 16, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,4 +62,6 @@ func main() { fmt.Println("Error adding cron job:", err) return } start() select {} } -
aashish-chaubey created this gist
Nov 16, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ package main import ( "fmt" "http://github.com/robfig/cron/v3" "sync" "time" ) func one() { fmt.Println("One") return } func two() { fmt.Println("Two") return } func three() { time.Sleep(5 * time.Second) fmt.Println("Three") return } func secondary_func(done chan bool) { defer close(done) one() two() three() } func main() { c := cron.New() _, err := c.AddFunc("*/2 * * * *", func() { users := []string{"user1", "user2", "user3"} var wg sync.WaitGroup for i := 0; i < len(users); i++ { wg.Add(1) go func(user string) { defer wg.Done() fmt.Println(user) done := make(chan bool) go secondary_func(done) select { case <-done: case <-time.After(2 * time.Second): fmt.Println("Goroutine timed out") } }(users[i]) } wg.Wait() }) if err != nil { fmt.Println("Error adding cron job:", err) return } }