Tiny little queue on top of SQLite written in Go.
sQueueLite is a simplistic, SQLite backed job embedded queue library for Go applications. It provides an easy way to manage and process background jobs, facilitating the scheduling and processing of tasks in an organized and efficient manner.
Warning Is still in heavy development and the API is not finalized yet and might change any moment.
go get github.com/risico/goqueuelite
package main
import "github.com/risico/goqueuelite"
func main() {
params := goqueuelite.Params{
DatabasePath: "queue.db",
AutoVacuum: true,
AutoPrune: true,
}
queue, err := goqueuelite.New(params)
if err != nil {
panic(err)
}
defer queue.Close()
}
data := "Your job data here"
params := goqueuelite.EnqueueParams{
Namespace: "test_namespace",
ScheduleAfter: time.Now().Add(1 * time.Hour),
TTL: 2 * time.Hour,
}
id, err := queue.Enqueue(data, params)
if err != nil {}
params := goqueuelite.DequeueParams{
Namespace: "default",
}
message, err := queue.Dequeue(params)
if err != nil {}
fmt.Printf("Message(%+v) \n", message)
type Message struct {
ID int64
Data any
Namespace string
Status JobStatus
Delay uint64
LockTime int
DoneTime int
Retries int
ScheduledAt int
TTL int
}
ch, err = queue.Subscribe("default")
if err != nil { }
for {
select {
case mEvent, ok := <-ch:
if !ok {
return
}
m, err := queue.Lock(mEvent.MessageID)
// do something with m
}
}
err = queue.Done(messageID)
if err != nil {
// handle error
}
err = queue.Fail(messageID)
if err != nil {
// handle error
}
err = queue.Retry(messageID)
if err != nil {
// handle error
}
size, err := queue.Size()
isEmpty, err := queue.Empty()
If you have disabled AutoPrune and AutoVacuum, you can manually prune and vacuum the database.
queue.Prune()
queue.Vacuum()
CGO is required and enabled by default as the package makes use of github.com/mattn/go-sqlite3 but if you require cross-compilation and don't want to bother with
CGO you can set the -tags nocgo (alongside CGO_ENABLED=0) and it will switch to using modernc.org/sqlite which does not require CGO.
go build . -tags nocgo
Feel free to contribute to this project by opening issues or submitting pull requests for bug fixes or features.
This project is licensed under the MIT License.