chiefnoah
/
goalpost
Archived
1
0
Fork 0
goalpost is an embeddable, durable worker queue for golang
You cannot 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
continuous-integration/drone/push Build is passing Details
Adds some clarification to docs
3 years ago
examples Adds example 3 years ago
.drone.yml Adds coverage to drone 4 years ago
.gitignore Initial commit 4 years ago
LICENSE Initial commit 4 years ago
README.md Adds example 3 years ago
go.mod Adds go.mod and go.sum files 4 years ago
go.sum Adds go.mod and go.sum files 4 years ago
job.go Adds some clarification to docs 3 years ago
queue.go Adds support for changing Sleep duration 3 years ago
queue_test.go Updates package 4 years ago
worker.go Adds some clarification to docs 3 years 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()
}