https://github.com/iflamed/mfworker
A memory and file based task worker for Golang. Queue jobs only for single process application.
https://github.com/iflamed/mfworker
golang queue queue-workers queued-jobs task-queue worker-queue
Last synced: about 1 month ago
JSON representation
A memory and file based task worker for Golang. Queue jobs only for single process application.
- Host: GitHub
- URL: https://github.com/iflamed/mfworker
- Owner: iflamed
- Created: 2019-11-29T07:06:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-22T14:48:14.000Z (over 5 years ago)
- Last Synced: 2025-01-25T09:11:12.683Z (3 months ago)
- Topics: golang, queue, queue-workers, queued-jobs, task-queue, worker-queue
- Language: Go
- Size: 31.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Golang mfworker
----------
> Mfworker is a memory and file based task worker for Golang.
> It's embeddable for golang project. So it's only work for single process application.## Features
1. Custom worker numbers.
2. Custom the number of jobs stored in memory.
3. Single process.
4. Thread safe.
5. Jobs will be store in memory first, then auto store jobs to badger db file.
6. Recoverable, when process exit, it will auto save jobs to file.## Demo
```go
package mainimport (
"log"
"strconv"
"time"
"github.com/iflamed/mfworker"
)func main() {
var (
count uint
maxItems uint
)
count = 4
maxItems = 16
path := "./test.db"
queueName := "mfworkder"
q := mfworker.NewQueue(count, maxItems, path, queueName, nil)
q.Handler("Test", func(job *mfworker.Job) {
time.Sleep(time.Second)
log.Printf("the job name %s, job body %s ", job.Name, job.Payload)
})
q.Start()
go func() {
for i := 0; i < 64; i++ {
job := &mfworker.Job{
Name: "Test",
Payload: []byte("body " + strconv.Itoa(i)),
}
q.Dispatch(job)
}
}()
<-time.After(10 * time.Second)
q.Stop()
}
```