jobq

package module
v0.0.0-...-f7a6c10 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 4 Imported by: 0

README

JobQ

Go Reference

Queue == Que == Q

A basic job queue implemented in Go.

Idea
  • Task is the basic unit of work that we want to run.
  • Job contains >= 1 related Task(s).
  • Queue contains jobs and determines how/when to execute certain Jobs.
  • JobQ is just a runner that runs ready Jobs.
Current Features
  1. Both Queue and Task are interfaces that you can easily implement and provide additional fields to.
  2. PriorityQueue is provided as a default to use with JobQ.
    • It is heap-based, so it implements the methods necessary for container/heap.
  3. Job.Priority can be anything as long as they can be converted/encoded to int (string, date, numbers, etc.).
  4. Jobs must run sequentially (due to priority), but tasks in a job can run either sequentially or concurrently.
Examples

Do take a look at jobq_test.go to see how JobQ is used.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Label      string
	Tasks      []Task
	Priority   int
	Concurrent bool
	// contains filtered or unexported fields
}

func (*Job) Run

func (j *Job) Run()

type JobQ

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

func NewJobQ

func NewJobQ(waitInterval time.Duration, queue Queue) *JobQ

func (*JobQ) Add

func (jq *JobQ) Add(job *Job)

func (*JobQ) Remove

func (jq *JobQ) Remove() *Job

func (*JobQ) Watch

func (jq *JobQ) Watch()

type PriorityQueue

type PriorityQueue []*Job

func (*PriorityQueue) HasReadyJob

func (pq *PriorityQueue) HasReadyJob() bool

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

For both Heap & Queue implementation

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

Heap Methods

func (*PriorityQueue) Peek

func (pq *PriorityQueue) Peek() *Job

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) PopJob

func (pq *PriorityQueue) PopJob() *Job

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (*PriorityQueue) PushJob

func (pq *PriorityQueue) PushJob(job *Job)

Queue Methods

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

func (*PriorityQueue) UpdateJob

func (pq *PriorityQueue) UpdateJob(item *Job, label string, tasks []Task, priority int)

type Queue

type Queue interface {
	PushJob(job *Job)
	PopJob() *Job
	UpdateJob(item *Job, label string, tasks []Task, priority int)
	Len() int
	Peek() *Job
	HasReadyJob() bool
}

type Task

type Task interface {
	Desc() string
	Run()
}

Jump to

Keyboard shortcuts

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