workque

package
v0.0.0-...-8f9fda8 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JobQueue chan Job

JobQueue a buffered channel that we can send work requests on.

Functions

This section is empty.

Types

type Data

type Data struct {
	Temperature string `json:"temperature"`
	Humidity    string `json:"humidity"`
}

Data a MQTT payload model

type Dispatcher

type Dispatcher struct {
	// A pool of workers channels that are registered with the dispatcher
	WorkerPool chan chan Job
	// contains filtered or unexported fields
}

Dispatcher struct of workers channels

func NewDispatcher

func NewDispatcher(maxWorkers int) *Dispatcher

NewDispatcher create new dispatcher

func (*Dispatcher) Run

func (d *Dispatcher) Run()

Run start the workers

type Job

type Job struct {
	DB      *db.DB
	Message *sarama.ConsumerMessage
}

Job represents the job to be run

func (*Job) InsertIntoDB

func (j *Job) InsertIntoDB() error

InsertIntoDB insert received data into database

type Worker

type Worker struct {
	WorkerPool chan chan Job
	JobChannel chan Job
}

Worker represents the worker that executes the job

func NewWorker

func NewWorker(workerPool chan chan Job) Worker

NewWorker create new channel worker

func (Worker) Start

func (w Worker) Start()

Start method starts the run loop for the worker, listening for a quit channel in case we need to stop it

func (Worker) Stop

func (w Worker) Stop(wg *sync.WaitGroup)

Stop signals the worker to stop listening for work requests.

Jump to

Keyboard shortcuts

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