https://github.com/pariola/sched
a simple scheduler (wip)
https://github.com/pariola/sched
priority-queue priority-scheduling scheduler
Last synced: 12 days ago
JSON representation
a simple scheduler (wip)
- Host: GitHub
- URL: https://github.com/pariola/sched
- Owner: pariola
- Created: 2021-12-11T21:06:27.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T00:11:39.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T16:55:27.445Z (over 1 year ago)
- Topics: priority-queue, priority-scheduling, scheduler
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sched
an attempt at creating a simple scheduler.
It relies on a priority queue (ex. Binary Heap) to maintain all the jobs needed to be scheduled.
### Features
- [ ] state persistence
- [x] cancel pending job
### In Action
```go
func main() {
s := sched.New(sched.Config{
N: 10,
Q: queue.BinaryHeap(),
Sink: func(id int, job sched.Job) {
fmt.Printf("by worker: %d | message: %s\n", id, job.Msg)
},
})
now := time.Now()
// queue messages
for i := 0; i < 5; i++ {
msg := fmt.Sprintf("msg %d", i)
s.Queue([]byte(msg), now.Add(3*time.Second))
}
jobOneId := s.Queue([]byte("missing!"), now.Add(2*time.Second))
s.Queue([]byte("You rock!"), now.Add(2*time.Second))
// cancel job
s.CancelJob(jobOneId)
}
```
Result:
```txt
by worker: 9 | message: You rock!
by worker: 4 | message: msg 3
by worker: 5 | message: msg 0
by worker: 6 | message: msg 1
by worker: 7 | message: msg 2
by worker: 8 | message: msg 4
```