Skip to content

A worker pool in GoLang which schedules job according to priority.

License

Notifications You must be signed in to change notification settings

kc596/priorityworkerpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Priority Worker Pool

Build Status codecov Go Report Card Maintainability

A worker pool in GoLang which schedules job according to priority.

Installation

go get github.com/kc596/priorityworkerpool

Quickstart

import "github.com/kc596/priorityworkerpool"

const (
	poolName   = "testPool"
	numWorkers = 1000
)

var panicHandler = func(alias string, err interface{}) {
	fmt.Println(alias, err) // or use logger
}

pool := priorityworkerpool.New(poolName, numWorkers, panicHandler)

job := func() {
	// code to execute
}

pool.Submit(job, 1+rand.Float64())

A complete example : Here

APIs

Method Return Type Description
New(name string, workers int, panicHandler func(alias string, err interface{}) *Pool Returns a new worker pool
Submit(job func(), priority float64) void Submit a new job to worker pool
WaitGroup() *sync.WaitGroup Returns waitgroup to wait for all jobs submitted to finish
ShutDown() void Delete queue and prevents pickup of next job from the queue