Skip to content
Proyek

Tentang

A sqlite based queue written in go

Data dan analisis

Cara angka ini diukur

Yang dapat Anda lakukan

  • FIFO and priority queues, one file per queue or all in one
  • Acknowledge and reject; a dead process's jobs return to the queue
  • Enqueue once per job ID
  • Batch claims in one statement

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
0
dalam 15 hari
0
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli
sqliteq

Durable job queues for Go, stored in SQLite.

Go Reference CI Codecov MIT

sqliteq gives you FIFO and priority queues in a SQLite file: no server to run, jobs survive restarts, and several processes on one host can share a queue. It is also the SQLite storage adapter for VarMQ.

Features

  • FIFO and priority queues, one file per queue or all in one
  • Acknowledge and reject; a dead process's jobs return to the queue
  • Enqueue once per job ID
  • Batch claims in one statement
  • Job outcome, cancel and pause, across processes
  • VarMQ workflows that survive a restart

Install

go get github.com/goptics/sqliteq

Needs Go 1.27+ and cgo (CGO_ENABLED=1, a C compiler) for mattn/go-sqlite3.

Quick start

package main

import (
	"fmt"
	"log"

	"github.com/goptics/sqliteq"
)

func main() {
	qs, err := sqliteq.New("data") // folder; one <name>.db per queue
	if err != nil {
		log.Fatal(err)
	}
	defer qs.Close()

	q, err := qs.NewQueue("jobs")
	if err != nil {
		log.Fatal(err)
	}

	q.Enqueue([]byte("hello"))

	if item, ok := q.Dequeue(); ok {
		fmt.Println(string(item.([]byte)))
	}
}

Usage

Priority

Lower number first.

pq, _ := qs.NewPriorityQueue("emails")
pq.Enqueue([]byte("newsletter"), 3)
pq.Enqueue([]byte("password reset"), 1)

item, _ := pq.Dequeue() // "password reset"

Acknowledge

A job you don't acknowledge returns to the queue if its process dies.

item, ok, ackID := q.DequeueWithAckId()
if ok {
	if err := process(item); err != nil {
		q.Reject(ackID, err.Error()) // failed for good, not requeued
	} else {
		q.Acknowledge(ackID)
	}
}

Batch: q.DequeueBatchWithAckIds(items, ackIDs) claims as many as both slices hold, in one statement.

Enqueue once

q.EnqueueOnce([]byte("send invoice 42"), "invoice-42") // stored
q.EnqueueOnce([]byte("send invoice 42"), "invoice-42") // true, nothing stored

With VarMQ

q, _ := qs.NewQueue("jobs")

worker := varmq.NewWorker(func(j varmq.Job[string]) {
	fmt.Println(j.Data())
})
defer worker.WaitAndStop()

worker.WithQueue(q).Add("hello")

Outcome, cancel, pause and inspection then work through VarMQ and its REST API. Needs VarMQ v1.11.0 or later.

Workflows

store, _ := sqliteq.NewWorkflowStore(qs)
defer store.Close() // before qs.Close

worker := varmq.NewErrWorker(func(j varmq.Job[string]) error { return nil })
defer worker.WaitAndStop()

wf := varmq.NewWorkflow(store)
a := wf.Add("resize", worker.WithQueue(resize), "photo.jpg")
wf.Add("publish", worker.WithQueue(publish), "photo.jpg").After(a)

wf.Submit(ctx)
record, _ := wf.Wait()

Full program: example/workflow_example.go.

Options

Option On Default Effect
WithSingleFile() New folder path is one file holding every queue
WithCheckpointPages(n) New 1000 WAL pages before a checkpoint; 10000 trades disk (about 41 MB) for throughput
WithHeartbeatTimeout(d) New 30s How long until a silent process's jobs are requeued; min 5s
WithRemoveOnComplete(false) NewQueue true Keep finished rows as completed / failed / cancelled

Guarantees

Call Guarantee
DequeueWithAckId, DequeueBatchWithAckIds At least once: unacked jobs return after the heartbeat timeout
Dequeue At most once: deleted when returned
EnqueueOnce Once per ID while its row exists
Enqueue Survives a process crash once it returns true
Acknowledge, Reject The finish and its outcome record commit together

Limits

  • At least once, not exactly once: make handlers idempotent.
  • No visibility timeout: a hung job keeps its slot while its process lives.
  • After a crash, jobs return one heartbeat timeout later, also on an immediate restart.
  • Cross-process events (outcome, cancel, resume) arrive by polling, within about 50 ms.
  • One host only; SQLite WAL does not work over a network file system.
  • No retry limit or dead-letter queue.
  • Upgrade every process that shares a file at the same time.

Docs

Contributing

Issues and pull requests are welcome. Run go test -race ./... before you send one; it needs cgo.

License

MIT

Jelajahi proyek terkait

Memuat…