cque

package module
v0.0.0-...-0708c3d Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: MIT Imports: 7 Imported by: 4

README

cque

cque is que library modified from que-go library to work with a local go channel locally. I would choose que-go over cque any day but as a Proof of Concept, I needed this.

cque is not production ready, use it at your own risk.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	IsQueueEmpty bool

	Result chan Result
	// contains filtered or unexported fields
}

Client is a Que client that can add jobs to the queue and remove jobs from the queue.

func NewQue

func NewQue() *Client

NewClient create our new local queue Note: we are creating 5000 queue as we expect this to not reach this high. If due to delay and this limit is reached, it may cause deadlock if all channels want to write This was implemented crudely as PoC so fixes should be considered if used in production. Eg: maybe a slice/array to store the jobs being added to the client and have a channel dedicated to pushing the job out to workers.

func (*Client) Enqueue

func (c *Client) Enqueue(j Job)

Enqueue adds a job to the queue.

type ErrorMsg

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

type Job

type Job struct {
	Type string
	// Args can be anything depends on the job
	Args interface{}
}

Job is a single unit of work for Que to perform.

func (*Job) Error

func (j *Job) Error(msg string)

We dont tolerate error, all error will be logged and discarded.

type Manager

type Manager struct {
	Interval time.Duration
	// contains filtered or unexported fields
}

Manager is a single "worker" that check for when the job channel is empty This is done by checking the workerstatus channel and look for instances where all workers are waiting for job. This also only works because channel in GO are FIFO so we can get latest workers statuses

func NewManager

func NewManager(ctx context.Context, workercount int, c *Client) *Manager

func (*Manager) Manage

func (m *Manager) Manage()

Start starts all of the Workers in the WorkerPool.

type Result

type Result struct {
	JobType string
	// Args can be anything depends on the job
	Result interface{}
}

Result is the output of a Job and can be used to send something back to mainthread.

type WorkFunc

type WorkFunc func(j *Job) error

generic WorkFunc is a function that performs a Job. If an error is returned, the job is reenqueued with exponential backoff.

type WorkMap

type WorkMap map[string]WorkFunc

WorkMap is a map of Job names to WorkFuncs that are used to perform Jobs of a given type.

type Worker

type Worker struct {
	Interval time.Duration
	// contains filtered or unexported fields
}

Worker is a single worker that pulls jobs off the specified Queue. If no Job is found, the Worker will sleep for Interval seconds.

func NewWorker

func NewWorker(ctx context.Context, id int, c *Client, m WorkMap) *Worker

func (*Worker) Work

func (w *Worker) Work()

Work pulls jobs off the Worker's Queue at its Interval. This function only returns after Shutdown() is called, so it should be run in its own goroutine.

func (*Worker) WorkOne

func (w *Worker) WorkOne(j *Job)

type WorkerPool

type WorkerPool struct {
	WorkMap  WorkMap
	Interval time.Duration
	// contains filtered or unexported fields
}

WorkerPool is a pool of Workers, each working jobs from the queue Queue at the specified Interval using the WorkMap.

func NewWorkerPool

func NewWorkerPool(c *Client, wm WorkMap, count int) *WorkerPool

NewWorkerPool creates a new WorkerPool with count workers using the Client c.

func (*WorkerPool) Start

func (w *WorkerPool) Start(ctx context.Context)

Start starts all of the Workers in the WorkerPool.

type WorkerWaitStatus

type WorkerWaitStatus struct {
	Id         int
	WaitStatus bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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