goalpost

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2019 License: MIT Imports: 10 Imported by: 0

README

goalpost

Build Status

Goalpost is a durable, embedable, worker queue for Golang.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Status     JobStatus
	ID         uint64
	Data       []byte
	RetryCount int
	Message    string
}

Job wraps arbitrary data for processing

func DecodeJob

func DecodeJob(b []byte) *Job

DecodeJob decodes a gob encoded byte array into a Job struct and returns a pointer to it

func (*Job) Bytes

func (j *Job) Bytes() []byte

Bytes returns a gob encoded byte array representation of *j

type JobStatus

type JobStatus int

JobStatus is a enumerated int representing the processing status of a Job

const (
	Ack JobStatus = iota + 1
	Uack
	Nack
	Failed
)

JobStatus types

type Queue

type Queue struct {
	ID string
	// contains filtered or unexported fields
}

Queue represents a queue

func Init

func Init(filepath string) (*Queue, error)

Init creates a connection to the internal database and initializes the Queue type

func (*Queue) Close

func (q *Queue) Close() error

Close attempts to gracefull shutdown all workers in a queue and shutdown the db connection

func (*Queue) GetJobByID

func (q *Queue) GetJobByID(id uint64) (*Job, error)

GetJobByID returns a pointer to a Job based on the primary key identifier id

func (*Queue) PushBytes

func (q *Queue) PushBytes(d []byte) (uint64, error)

PushBytes wraps arbitrary binary data in a job and pushes it onto the queue

func (*Queue) PushJob

func (q *Queue) PushJob(j *Job) (uint64, error)

PushJob pushes a job to the queue and notifies workers Job.ID is always overwritten

func (*Queue) RegisterWorker

func (q *Queue) RegisterWorker(w Worker)

RegisterWorker registers a Worker to handle queued Jobs

func (*Queue) UpdateJobStatus

func (q *Queue) UpdateJobStatus(id uint64, status JobStatus, message string) error

UpdateJobStatus updates the processing status of a job

type RecoverableWorkerError

type RecoverableWorkerError struct {
	// contains filtered or unexported fields
}

RecoverableWorkerError defines an error that a worker DoWork func can return that indicates the message should be retried

func NewRecoverableWorkerError

func NewRecoverableWorkerError(message string) RecoverableWorkerError

NewRecoverableWorkerError creates a new RecoverableWorkerError

func (RecoverableWorkerError) Error

func (e RecoverableWorkerError) Error() string

type Worker

type Worker interface {
	DoWork(context.Context, *Job) error
	ID() string
}

Worker represents a worker for handling Jobs

type WorkerConfig

type WorkerConfig struct {
	//PollingRate is the number of milliseconds to sleep after checking the queue for a job
	PollingRate uint8
}

WorkerConfig configures a worker

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL