spy16 / genie

Genie is a simple job-queue library/framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🧞 Genie

Genie is a dead simple job-queue library/tool.

Usage

import "github.com/spy16/genie"

func main() {
    // connect to sqlite3.
    q, err := genie.Open("sqlite3://my-queue.db", nil)
    if err != nil {
        panic(err)
    }
    defer q.Close()


    // enqueue items on the queue.
    // this can be exposed as http api or something.
    _ = q.Push(ctx, Item{
        ID: "job1",
        Type:"job-category",
        Payload:"arbitrary data for executing job",
    })

    // run the poll-excute loop
    log.Fatalf("exited: %v", q.Run(ctx, myExecutorFunc))
}

func myExecutorFunc(ctx context.Context, item genie.Item) error {
    // do your thing

    return nil
    // return genie.ErrFail to fail immediately
    // return genie.ErrSkip to skip this item
    // return any other error to signal retry.
}

About

Genie is a simple job-queue library/framework.

License:MIT License


Languages

Language:Go 79.3%Language:HTML 20.1%Language:Makefile 0.6%