pooler

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT, MIT Imports: 7 Imported by: 0

README

pooler

Tricky and fun utilities for Go programs.


GitHub Workflow Status Codecov

Contributor Covenant

Twitter Follow GitHub followers


Getting Started

Prerequisites

Developed with $( go version; ). Go is extremely backwards compatible and semver stable. Nearly any v1.x should work fine.


Installation

To use this repo as a template for your own project:

gh repo create -y --public --template "https://github.com/skeptycal/pooler"

Clone this repo to test and contribute:

# add repo to $GOPATH (xxxxxx is your computer login username)
go get github.com/xxxxxx/pooler

cd ${GOPATH}/src/github.com/xxxxxx/pooler

# test results and coverage info
./go.test.sh

# install as a utility package
go install

Use the Issues and PR templates on the GitHub repo page to contribute.


Basic Usage

This is a copy of the example script available in the cmd/example/pooler folder:

package main

import "github.com/skeptycal/pooler"

func main() {
    pooler.Example()
}

To try it out:

# change to the sample folder
cd cmd/example/pooler

# run the main.go program
go run ./main.go

# to compile as an executable
go build

Code of Conduct and Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us. Please read the Code of Conduct for details before submitting anything.


Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.


Contributors and Inspiration

  • Michael Treanor (GitHub / Twitter) - Initial work, updates, maintainer
  • Francesc Campoy - Inspiration and great YouTube videos!

See also the list of contributors who participated in this project.


License

Licensed under the MIT https://opensource.org/licenses/MIT - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const SIZE = 5 // size of cache

Variables

View Source
var WorkerChannel = make(chan chan Work)

Functions

func CreateExampleJobs

func CreateExampleJobs(amount int) []string

CreateExampleJobs mimics the creation of 'amount' concurrent jobs.

func Example

func Example()

func ExampleWork

func ExampleWork(params Params) error

ExampleWork mimics any type of job that can be run concurrently

func RandStringRunes

func RandStringRunes(n int) string

Types

type Any

type Any interface{}

type Cache

type Cache struct {
	Queue Queue
	Hash  Hash
}

func NewCache

func NewCache() Cache

func (*Cache) Add

func (c *Cache) Add(n *Node)

func (*Cache) Check

func (c *Cache) Check(str string)

func (*Cache) Display

func (c *Cache) Display()

func (*Cache) Remove

func (c *Cache) Remove(n *Node) *Node

type Collector

type Collector struct {
	Work chan Work
	End  chan bool
}

func StartDispatcher

func StartDispatcher(workerCount int) Collector

type GetSetter

type GetSetter interface {
	Get(key Any) (Any, error)
	Set(key Any, value Any) error
}

type Hash

type Hash map[string]*Node

maps string to node in Queue

type JobSpec

type JobSpec interface {

	// Identifier is the main unique identifier associated
	// with this specific job specification. It may be
	// considered analogous to a primary key in a database.
	Identifier() Any

	// Name is an optional text name for this job that will
	// be used in error messages and reports.
	Name() string

	// ID is an optional unique identifier for this job. It
	// may be used when sorting and searching performance
	// will be hindered by using an interface{}.
	Id() int

	// Completed tags the job specification as completed.
	// Not all workers may have finished, but the goals of
	// the job specification have been reached. All work is
	// stopped and no further work will be performed.
	Completed() bool

	// Deadline is an optional time at which the job spec
	// expires and no more work will be performed towards
	// the goals of this job specification.
	Deadline() time.Time
}

type Node

type Node struct {
	Val   string
	Left  *Node
	Right *Node
}

type Params

type Params interface {
	GetSetter
}

func NewParams

func NewParams(locked bool, m map[string]Any) Params

type Queue

type Queue struct {
	Head   *Node
	Tail   *Node
	Length int
}

double linked list

func NewQueue

func NewQueue() Queue

func (*Queue) Display

func (q *Queue) Display()

type Work

type Work struct {
	ID  int
	Job string
	JS  JobSpec
}

type Worker

type Worker interface {
	Start()
	Stop()
	DoWork(params Params)
}

Jump to

Keyboard shortcuts

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