Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlite

package
v0.56.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sqlite is the default queue driver, sharing the filex DB file with the metadata store. It uses BEGIN IMMEDIATE for the dequeue fast-path; SQLite's single-writer semantics make this race-free under the typical single-node deployment. For HA setups switch to the postgres driver via FILEMANAGER_QUEUE_DRIVER=postgres.

It also serves MySQL/MariaDB, registered under the name "mysql". The placeholder syntax and every statement here are shared; the three expressions that ask the server for the current time are not, and go through nowExpr/nowOffset. ⚠ Before issue #19 a MySQL install got this driver in its SQLite spelling, so every poll logged a syntax error and no queued job — content extraction, antivirus scans, replica retries — ever ran, on a server that otherwise looked healthy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is the SQLite-backed queue — and, in mysql mode, the MySQL/MariaDB one.

func (*Driver) Ack

func (d *Driver) Ack(ctx context.Context, id string) error

Ack marks the op done.

func (*Driver) Cancel

func (d *Driver) Cancel(ctx context.Context, id string) error

Cancel transitions a pending op to cancelled.

func (*Driver) Close

func (d *Driver) Close() error

Close releases the underlying *sql.DB only when this driver opened it (cfg["dsn"] path). When wired against the application's shared *sql.DB (cfg["db"]), Close is a no-op so we don't tear down the metadata store.

func (*Driver) Dequeue

func (d *Driver) Dequeue(ctx context.Context, types []string) (queue.Op, error)

Dequeue uses an UPDATE-with-subquery RETURNING (SQLite ≥ 3.35) to atomically claim the next eligible op for a worker.

func (*Driver) Enqueue

func (d *Driver) Enqueue(ctx context.Context, op queue.Op) (string, error)

Enqueue inserts an op and returns its id.

func (*Driver) Fail

func (d *Driver) Fail(ctx context.Context, id, errMsg string, retry bool) error

Fail records the failure. retry=true requeues; retry=false terminates.

func (*Driver) Get

func (d *Driver) Get(ctx context.Context, id string) (queue.Op, error)

Get fetches a single op.

func (*Driver) Init

func (d *Driver) Init(_ context.Context, cfg map[string]any) error

Init opens the queue's DB. cfg keys:

dsn  — SQLite connection string. Required.
      Pass the same DSN as the metadata store to share one file.
db   — *sql.DB (optional). When set, dsn is ignored. Used by the
      bootstrap path that already has the application *sql.DB
      handle.

func (*Driver) List

func (d *Driver) List(ctx context.Context, status string, limit, offset int) ([]queue.Op, int64, error)

List returns ops with optional status filter and pagination.

func (*Driver) Name

func (d *Driver) Name() string

Name implements queue.Driver.

func (*Driver) RecoverOrphans

func (d *Driver) RecoverOrphans(ctx context.Context, olderThan time.Duration) (int64, error)

RecoverOrphans flips long-running rows back to pending. Called on boot to handle ungraceful shutdowns.

func (*Driver) Retry

func (d *Driver) Retry(ctx context.Context, id string) error

Retry transitions a failed op back to pending. The attempts counter is preserved so the operator can see how many tries it took.

func (*Driver) Stats

func (d *Driver) Stats(ctx context.Context) (queue.Stats, error)

Stats returns the dashboard counters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL