Swig 🍺

Installation

How to install and set up Swig

Installation

Prerequisites

  • Go 1.23 or later
  • PostgreSQL 15 or later

Installation

go get github.com/glamboyosa/swig@v0.1.17-alpha

Database Setup

Swig requires a PostgreSQL database to store job information. It will automatically create the necessary swig_jobs table if it doesn't already exist.

The table schema is as follows. You typically do not need to interact with this table directly.

CREATE TABLE IF NOT EXISTS swig_jobs (
    id BIGSERIAL PRIMARY KEY,
    kind TEXT NOT NULL,
    queue TEXT NOT NULL,
    payload JSONB NOT NULL,
    status TEXT NOT NULL DEFAULT 'pending',
    priority INTEGER NOT NULL DEFAULT 0,
    run_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
 
CREATE INDEX IF NOT EXISTS idx_swig_jobs_status ON swig_jobs (status);
CREATE INDEX IF NOT EXISTS idx_swig_jobs_queue ON swig_jobs (queue);
CREATE INDEX IF NOT EXISTS idx_swig_jobs_run_at ON swig_jobs (run_at);

Choose Your Driver

Swig supports two PostgreSQL driver implementations:

import (
    "github.com/jackc/pgx/v5/pgxpool"
    "github.com/glamboyosa/swig/drivers"
)
 
// Setup pgx connection
pgxConfig, _ := pgxpool.ParseConfig("postgres://localhost:5432/myapp")
pgxPool, _ := pgxpool.NewWithConfig(ctx, pgxConfig)
driver, _ := drivers.NewPgxDriver(pgxPool)

Benefits:

  • Better performance
  • Native LISTEN/NOTIFY support
  • Real-time job notifications

Next Steps

On this page