Swig 🍺

API Reference

Detailed API documentation for Swig

API Reference

Core Types

Swig

The main type that manages job processing.

type Swig struct {
    driver          Driver
    swigQueueConfig []SwigQueueConfig
    Workers         WorkerRegistry
    // ... internal fields
}

SwigQueueConfig

Configuration for a queue type.

type SwigQueueConfig struct {
    QueueType  QueueTypes
    MaxWorkers int
}

JobOptions

Options for job processing.

type JobOptions struct {
    Queue    QueueTypes
    Priority int
    RunAt    time.Time
}

BatchJob

A job to be processed in a batch.

type BatchJob struct {
    Worker Worker
    Opts   JobOptions
}

Core Functions

NewSwig

Creates a new Swig instance.

func NewSwig(driver Driver, configs []SwigQueueConfig, workers WorkerRegistry) *Swig

Start

Starts processing jobs.

func (s *Swig) Start(ctx context.Context)

Stop

Stops processing jobs.

func (s *Swig) Stop(ctx context.Context) error

AddJob

Adds a single job.

func (s *Swig) AddJob(ctx context.Context, worker Worker, opts ...JobOptions) error

AddJobs

Adds multiple jobs in a single operation.

func (s *Swig) AddJobs(ctx context.Context, jobs []BatchJob) error

AddJobWithTx

Adds a job within a transaction.

func (s *Swig) AddJobWithTx(ctx context.Context, tx interface{}, worker Worker, opts ...JobOptions) error

AddJobsWithTx

Adds multiple jobs within a transaction.

func (s *Swig) AddJobsWithTx(ctx context.Context, tx interface{}, jobs []BatchJob) error

WithTx

Executes a function within a transaction.

func (s *Swig) WithTx(ctx context.Context, fn func(tx interface{}) error) error

Driver Interface

The Driver interface defines the contract for database operations:

type Driver interface {
    WithTx(ctx context.Context, fn func(tx Transaction) error) error
    Exec(ctx context.Context, sql string, args ...interface{}) error
    Query(ctx context.Context, sql string, args ...interface{}) (Rows, error)
    QueryRow(ctx context.Context, sql string, args ...interface{}) Row
    Listen(ctx context.Context, channel string) error
    Notify(ctx context.Context, channel string, payload string) error
    AddJobWithTx(ctx context.Context, tx interface{}) (Transaction, error)
    WaitForNotification(ctx context.Context) (*Notification, error)
    AddJobsWithTx(ctx context.Context, tx interface{}, jobs []BatchJob) error
}

Worker Interface

The Worker interface defines the contract for job processing:

type Worker interface {
    JobName() string
    Process(ctx context.Context) error
}

Constants

const (
    Default  QueueTypes = "default"
    Priority QueueTypes = "priority"
)

Next Steps

  • Examples - See Swig in action with practical examples
  • Configuration - Learn how to configure Swig for your needs

On this page