https://github.com/gintec-rdl/rtm
Resident Task Manager for golang
https://github.com/gintec-rdl/rtm
background-worker go-routine in-memory task-manager task-runner
Last synced: 5 months ago
JSON representation
Resident Task Manager for golang
- Host: GitHub
- URL: https://github.com/gintec-rdl/rtm
- Owner: gintec-rdl
- License: mit
- Created: 2024-03-20T08:44:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T10:15:43.000Z (over 2 years ago)
- Last Synced: 2024-06-21T08:29:20.982Z (about 2 years ago)
- Topics: background-worker, go-routine, in-memory, task-manager, task-runner
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rtm
Resident Task Manager for golang
#### Use case
You want to run parallel background tasks and you don't care about in memory data loss.
#### Goodies
- ✅ Offers parallel task execution by default
- ✅ Refined cancellation mechanism to prevent runaway go-routines and leaks.
- ✅ Crash recovery guarantees misbehaving and naughty tasks get booted off the pool
- ✅ Unbounded FIFO ring-buffer based backup [queue](https://github.com/eapache/queue) so you can run tasks later when execution pool size drops.
#### Caveats
- ❌ In Memory Only: Tasks and data do not persist.
- ❌ When cancelling task execution, the calling thread will block indefinitely to wait for all tasks in the executiono pool to finish. Note that tasks on the backup queue are simply dicarded since they never executed.
**Example**
```go
package main
import (
"fmt"
"github.com/gintec-rdl/rtm"
"math/rand"
"os"
"time"
)
func main() {
tasks := 100
poolSize := 5
te := rtm.NewTaskExecutor(poolSize)
task := func(ctx *rtm.TaskContext) {
index := ctx.Args["index"].(int)
fmt.Printf("[%d] enter\n", index)
// perform some time consuming action
time.Sleep(time.Duration(rand.Intn(5000)) * time.Millisecond)
// simulate a crash
if rand.Intn(2) == 1 {
panic(fmt.Errorf("[%d] crashed", index))
}
fmt.Printf("[%d] leave\n", index)
}
for i := 0; i < tasks; i++ {
params := rtm.TaskArguments{"index": i}
te.Queue(task, params)
}
time.Sleep(5 * time.Second)
te.Shutdown()
}
```