jobqueue

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 11 Imported by: 2

README

go-jobqueue

Codecov Go Report Card Go Reference


A lightweight, durable, and embedded job queue for Go applications. Powered by BadgerDB.

Warning: this package is a work in progress, use at your own risk.

Features

  • Portable alternative to full-fledged message brokers (i.e. RabbitMQ).
  • Built on top of BadgerDB for durability
  • Automatic job processing with support for multiple concurrent workers.
  • Strong type safety using generics.

Installation

go get github.com/argus-labs/go-jobqueue

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobContext

type JobContext interface {
	JobID() uint64
	JobCreatedAt() time.Time
}

JobContext provides context for a job which is injected into the job Process method.

type JobQueue

type JobQueue[T any] struct {
	// contains filtered or unexported fields
}

func New added in v0.1.4

func New[T any](
	dbPath string, name string, workers int, handler func(JobContext, T) error, opts ...Option[T],
) (*JobQueue[T], error)

New creates a new JobQueue with the specified database, name, and number of worker goroutines. It initializes the job queue, starts the worker goroutines, and returns the JobQueue instance and an error, if any.

func (*JobQueue[T]) Enqueue

func (jq *JobQueue[T]) Enqueue(payload T) (uint64, error)

func (*JobQueue[T]) Stop

func (jq *JobQueue[T]) Stop() error

type JobStatus

type JobStatus string
const (
	JobStatusPending   JobStatus = "pending"
	JobStatusCompleted JobStatus = "complete"
)

type Option

type Option[T any] func(*JobQueue[T])

func WithFetchInterval

func WithFetchInterval[T any](interval time.Duration) Option[T]

WithFetchInterval sets the interval at which the job queue fetches jobs from BadgerDB.

func WithInmemDB added in v0.1.5

func WithInmemDB[T any]() Option[T]

WithInmemDB uses an in-memory BadgerDB instead of a persistent one. Useful for testing, but provides no durability guarantees.

func WithJobBufferSize added in v0.1.3

func WithJobBufferSize[T any](size int) Option[T]

WithJobBufferSize sets the size of the job channel.

Jump to

Keyboard shortcuts

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