https://github.com/skvoch/reter
Task scheduler with synchronization over etcd
https://github.com/skvoch/reter
ectd-locks etcd golang lock locking sheduler task-scheduler
Last synced: 3 months ago
JSON representation
Task scheduler with synchronization over etcd
- Host: GitHub
- URL: https://github.com/skvoch/reter
- Owner: skvoch
- License: mit
- Created: 2021-01-23T17:30:53.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-05-11T15:19:34.000Z (almost 4 years ago)
- Last Synced: 2024-06-19T20:51:50.076Z (almost 2 years ago)
- Topics: ectd-locks, etcd, golang, lock, locking, sheduler, task-scheduler
- Language: Go
- Homepage:
- Size: 7.69 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reter - task scheduler with synchronization over etcd

### Installation
```bash
go get github.com/skvoch/reter
```
### Algorithm
1. Checking the time since the last action
2. If the difference between time.Now() and last action time less than interval - skipping
3. Locking and calling a handler function
4. Updating last action time, and unlocking
### Example
```go
s, err := scheduler.New(zerologadapter.NewLogger(log.Logger), &scheduler.Options{
Etcd: scheduler.EtcdOptions{
Endpoints: []string{"127.0.0.1:2379"},
},
LockTTL: time.Minute * 1,
Timeout: time.Second * 10,
})
if err != nil {
log.Fatal().Err(err).Msg("failed to connect to etcd")
}
g, ctx := errgroup.WithContext(context.Background())
g.Go(func() error {
return s.Every(30).Seconds().Do(ctx, "seconds", func() {
fmt.Println("print every 10 second")
})
})
g.Go(func() error {
return s.Every().Interval(time.Second*3).Do(ctx, "interval", func() {
fmt.Println("print every 3 second")
})
})
```
### Logging
Package contains several adapters for the most popular loggers:
* go-kit
* log15
* logrus
* zap
* zerolog