server

package
v0.0.0-...-3e52a38 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartServer

func StartServer(d *Dispatcher)

StartServer start an web server, which can be used to control the jobs

Types

type Dispatcher

type Dispatcher struct {
	// A pool of workers channels that are registered with the dispatcher
	WorkerPool chan chan Job
	MaxWorkers int
	Workers    []Worker
	JobQueue   chan Job // A buffered channel that we can send work requests on.
	// contains filtered or unexported fields
}

Dispatcher Keeps the things together, a controller.

func NewDispatcher

func NewDispatcher(maxWorkers, maxQueue int, p ProcessPayload) *Dispatcher

NewDispatcher Create a new instance

func (*Dispatcher) DispatchJob

func (d *Dispatcher) DispatchJob(j *Job)

DispatchJob send a job to the workers

func (*Dispatcher) Run

func (d *Dispatcher) Run()

Run start listening and hire the workers

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop Why you ever want to stop?

type Job

type Job struct {
	Payload Payload
}

Job represents the task/job to be run, with the payload

type Payload

type Payload struct {
	Magic string
}

Payload the data to be processed, in this example is a string

type ProcessPayload

type ProcessPayload func(w *Worker, p Job) error

ProcessPayload what to do with it?

type Worker

type Worker struct {
	WorkerPool chan chan Job
	JobChannel chan Job

	ID string //for debuging purposes
	// contains filtered or unexported fields
}

Worker represents the worker that executes the job

func NewWorker

func NewWorker(workerPool chan chan Job, p ProcessPayload) Worker

NewWorker workers are the foundation of our queue system

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()

Stop signals the worker to stop listening for work requests.

type WorkerUpdate

type WorkerUpdate struct {
	WorkerID string `json:"WorkerID"`
	Status   string `json:"Status"`
}

WorkerUpdate worker status update msg to clients

Jump to

Keyboard shortcuts

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