goalpost is an embeddable, durable worker queue for golang
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
Noah Pederson 80e278045c Adds some clarification to docs 1 month ago
examples Adds example 1 month ago
.drone.yml Adds coverage to drone 1 month ago
.gitignore Initial commit 1 month ago
LICENSE Initial commit 1 month ago
README.md Adds example 1 month ago
go.mod Adds go.mod and go.sum files 1 month ago
go.sum Adds go.mod and go.sum files 1 month ago
job.go Adds some clarification to docs 1 month ago
queue.go Adds support for changing Sleep duration 1 month ago
queue_test.go Updates package 1 month ago
worker.go Adds some clarification to docs 1 month ago

README.md

goalpost

Build Status

Goalpost is a durable, embedable, worker queue for Golang

It makes use of boltdb/bbolt to provide durability so messages don’t get lost when the process get’s killed.

Quickstart

Below is a simple use of goalpost:

package main

import (
	"context"
	"fmt"
	"time"
)
import "git.packetlostandfound.us/chiefnoah/goalpost"

const eventQueueID = "event-queue"

//Define a type that implements the goalpost.Worker interface
type worker struct {
	id string
}

func (w *worker) ID() string {
	return w.id
}

func (w *worker) DoWork(ctx context.Context, j *goalpost.Job) error {
	//do something cool!
	fmt.Printf("Hello, %s\n", j.Data)
	//Something broke, but we should retry it...
	if j.RetryCount < 9 { //try 10 times
		return goalpost.NewRecoverableWorkerError("Something broke, try again")
	}

	//Something *really* broke, don't retry
	//return errors.New("Something broke, badly")

	//Everything's fine, we're done here
	return nil
}

func main() {

	//Init a queue
	q, _ := goalpost.Init(eventQueueID)
	//remember to handle your errors :)

	//Create a worker with id "worker-id"
	w := &worker{
		id: "worker-1",
	}
	//register the worker, so it can do work
	q.RegisterWorker(w)

	//Let's do some work...
	q.PushBytes([]byte("World"))
	//You should see "Hello, World" printed 10 times

	//Make sure your process doesn't exit before your workers can do their work
	time.Sleep(10 * time.Second)

	//Remember to close your queue when you're done using it
	q.Close()
}