Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhashkevych/scheduler
Golang tool for scheduling functions execution within a given interval
https://github.com/zhashkevych/scheduler
go golang golang-library golang-tools task-scheduler
Last synced: 2 months ago
JSON representation
Golang tool for scheduling functions execution within a given interval
- Host: GitHub
- URL: https://github.com/zhashkevych/scheduler
- Owner: zhashkevych
- License: mit
- Created: 2019-05-10T15:28:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-14T20:34:03.000Z (almost 3 years ago)
- Last Synced: 2024-11-01T23:30:34.597Z (3 months ago)
- Topics: go, golang, golang-library, golang-tools, task-scheduler
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 48
- Watchers: 3
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Go Scheduler
================================## Blog Post
Go Scheduler helps you to manage functions that should be executed every N seconds/minutes/hours etc.
See it in action:
## Example #1
```go
package mainimport (
"fmt"
"time"
"os"
"os/signal"
"context"
"github.com/zhashkevych/scheduler"
)func main() {
ctx := context.Background()worker := scheduler.NewScheduler()
worker.Add(ctx, parseSubscriptionData, time.Second*5)
worker.Add(ctx, sendStatistics, time.Second*10)quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Interrupt)<-quit
worker.Stop()
}func parseSubscriptionData(ctx context.Context) {
time.Sleep(time.Second * 1)
fmt.Printf("subscription parsed successfuly at %s\n", time.Now().String())
}func sendStatistics(ctx context.Context) {
time.Sleep(time.Second * 5)
fmt.Printf("statistics sent at %s\n", time.Now().String())
}```
## Example #2
```go
package mainimport (
"context"
"fmt"
"os"
"os/signal"
"time""github.com/zhashkevych/scheduler"
)func main() {
ctx := context.Background()sc := scheduler.NewScheduler()
sc.Add(ctx, testFunc, time.Second*2)quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)<-quit
worker.Stop()
}func testFunc(ctx context.Context) {
ctx, _ = context.WithTimeout(ctx, time.Second*5)i := 0
for {
time.Sleep(time.Millisecond * 100)
i++
fmt.Printf("%d ", i)select {
case <-ctx.Done():
fmt.Println()
return
default:
}
}
}
```