jobqueue

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 5 Imported by: 1

README

JobQueue - Powerful unlimited job queue with goroutine pool

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/jobqueue

Getting Started

import (
  "testing"
  "github.com/go-zoox/jobqueue"
)

func main(t *testing.T) {
	q := New(runtime.NumCPU())
	q.Start()
	defer q.Stop()

	for i := 0; i < 10; i++ {
		q.AddJob(&NewJob(func() {
			fmt.Println("Process Job")
		}))
	}
}

Inspired by

  • dirkaholic/kyoo - Unlimited job queue for go, using a pool of concurrent workers processing the job queue entries

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

View Source
const (
	// JobStatusPending means the job is waiting to be processed.
	JobStatusPending = iota
	// JobStatusRunning means the job is being processed.
	JobStatusRunning
	// JobStatusDone means the job has been processed.
	JobStatusDone
	// JobStatusFailed means the job has failed to be processed.
	JobStatusFailed
)

Variables

View Source
var Version = "1.0.1"

Version is the current version of the package.

Functions

This section is empty.

Types

type Job

type Job interface {
	Process()
	Status(status int, err error)
}

Job interface for job processing

func NewJob

func NewJob(task func(), status ...func(status int, err error)) Job

NewJob creates a new job

type JobQueue

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

JobQueue is a queue for jobs

func New

func New(maxWorkers int) *JobQueue

New creates a new job queue

func (*JobQueue) AddJob

func (q *JobQueue) AddJob(job Job)

AddJob adds a job to the queue

func (*JobQueue) Quit added in v1.0.1

func (q *JobQueue) Quit()

Quit quits the job queue

func (*JobQueue) Run added in v1.0.1

func (q *JobQueue) Run() (err error)

Run runs the job queue

func (*JobQueue) Start

func (q *JobQueue) Start()

Start starts the job queue

func (*JobQueue) Stop

func (q *JobQueue) Stop()

Stop stops the job queue

type Worker

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

Worker is a worker for job processing

func NewWorker

func NewWorker(readyPool chan chan Job, done *sync.WaitGroup) *Worker

NewWorker creates a new worker

func (*Worker) Start

func (w *Worker) Start()

Start starts the worker

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops the worker

Jump to

Keyboard shortcuts

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