remoteworkers

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2016 License: MIT Imports: 9 Imported by: 0

README

remoteworkers

Package remoteworkers provides features for executing the same job on all the workers and collects results from workers.

You can see the API document at https://godoc.org/github.com/hnakamur/remoteworkers

License

MIT

Documentation

Overview

Package remoteworkers provides features for executing the same job on all the workers and collects results from workers.

Workers must connect to the server with websockets and keep the connection active. When the server is down, workers tries reconnecting to the server.

When the server receives a job from a client, the server sends the job to all workers and receives the result. When the server receives results from all the workers, the server sends the results to the client.

When connections are lost for some workers, the server sends a job to only workers whose connection is active. Also when a connection is lost after sending a job to a worker, the server does not wait for the worker. When the server receives results from all active workers, the server sends results to the client.

You can see an example at https://github.com/hnakamur/remoteworkers/tree/master/example

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is an middleman between the websocket connection and the hub.

func NewConn

func NewConn(ws *websocket.Conn, workerID string, logger ltsvlog.LogWriter, config ConnConfig) *Conn

NewConn creates a new connection.

func (*Conn) RegisterToHub

func (c *Conn) RegisterToHub(h *Hub) error

RegisterToHub registers this connection to a hub.

func (*Conn) Run

func (c *Conn) Run()

Run runs a connection.

type ConnConfig

type ConnConfig struct {
	// SendChannelLen is length of send channel.
	SendChannelLen int

	// WriteWait is time allowed to write a message to the worker.
	WriteWait time.Duration

	// PongWait is time allowed to read the next pong message from the worker.
	PongWait time.Duration

	// PingPeriod is period which the connection pings to worker with. Must be less than PongWait.
	PingPeriod time.Duration

	// Maximum message size allowed from worker.
	MaxMessageSize int64
}

ConnConfig is a configuration for Conn.

func DefaultConnConfig

func DefaultConnConfig() ConnConfig

DefaultConnConfig returns the default config for Conn.

type Hub

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

Hub maintains the set of active connections and broadcasts messages to the connections.

func NewHub

func NewHub(logger ltsvlog.LogWriter) *Hub

NewHub creates a hub

func (*Hub) RequestWork

func (h *Hub) RequestWork(params interface{}) (map[string]interface{}, uint64, error)

RequestWork sends a job to all remote workers and receives results from all workers. It returns the results and the job ID which will be issued by the hub.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context) error

Run runs a hub.

type WorkFunc

type WorkFunc func(params interface{}) interface{}

WorkFunc is a function type for a worker to work.

type Worker

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

Worker is the type for workers.

func NewWorker

func NewWorker(serverURL url.URL, workerIDHeaderName, workerID string, workFunc WorkFunc, logger ltsvlog.LogWriter, config WorkerConfig) *Worker

NewWorker creates a worker.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Run runs a worker. The worker connects to the remote server over the websocket. Then it waits for a job to be sent from the server and does a work and sends the result to the server. If the connection is lost, the worker tries to reconnect to the server after the delay specified in config.DelayBeforeReconnecting passed to NewWorker.

type WorkerConfig

type WorkerConfig struct {
	SendChannelLen          int
	DelayAfterSendingClose  time.Duration
	DelayBeforeReconnecting time.Duration
}

WorkerConfig is the configuration for workers.

func DefaultWorkerConfig

func DefaultWorkerConfig() WorkerConfig

DefaultWorkerConfig returns the default config for workers.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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