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 //Unique identifier for a Job ID uint64 //Data contains the bytes that were pushed using Queue.PushBytes() Data []byte //RetryCount is the number of times the job has been retried //If your work can have a temporary failure state, it is recommended //that you check retry count and return a fatal error after a certain //number of retries RetryCount int //Message is primarily used for debugging. It conatains status info //about what was last done with the job. Message string }
Job wraps arbitrary data for processing
type JobStatus ¶
type JobStatus int
JobStatus is a enumerated int representing the processing status of a Job
type Queue ¶
type Queue struct { //ID is a unique identifier for a Queue ID string //PollRate the duration to Sleep each worker before checking the queue for jobs again //queue for jobs again. //Default: 500 milliseconds PollRate time.Duration // contains filtered or unexported fields }
Queue represents a queue
func Init ¶
Init creates a connection to the internal database and initializes the Queue type filepath must be a valid path to a file. It cannot be shared between instances of a Queue. If the file cannot be opened r/w, an error is returned.
func (*Queue) Close ¶
Close attempts to gracefull shutdown all workers in a queue and shutdown the db connection
func (*Queue) GetJobByID ¶
GetJobByID returns a pointer to a Job based on the primary key identifier id It first checks active jobs, if it doesn't find the bucket for active jobs it searches in the completed jobs bucket.
func (*Queue) PushBytes ¶
PushBytes wraps arbitrary binary data in a job and pushes it onto the queue
func (*Queue) PushJob ¶
PushJob pushes a job to the queue and notifies workers Job.ID is always overwritten
func (*Queue) RegisterWorker ¶
RegisterWorker registers a Worker to handle queued Jobs
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 is called when a worker picks up a job from the queue //Context can be used for cancelling jobs early when Close //is called on the Queue DoWork(context.Context, *Job) error //ID is a semi-unique identifier for a worker //it is primarily used for logging purposes ID() string }
Worker represents a worker for handling Jobs