internal

package
v0.0.0-...-10cdc12 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caller

type Caller interface {
	Call(ctx context.Context, request liteproto.TaskRequest, deadline time.Time) (err error)
}

Caller makes a call to a remote server to execute a task. It is used by a Runner to make the call. This enables abstraction of remote server calls.

type Feeder

type Feeder interface {
	Feed(ctx context.Context, request liteproto.TaskRequest, deadline time.Time) error
}

Feeder accepts new task execution requests. Deadline parameter should be zero time if it's not needed (equal to time.Time{}).

type PubSub

type PubSub struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PubSub is a simple implementation of publisher/subscriber interface that stores all subscribers into a in-memory map. It doesn't support horizontal scaling of servers.

func (*PubSub) Publish

func (q *PubSub) Publish(response liteproto.TaskResponse) (err error)

func (*PubSub) Subscribe

func (q *PubSub) Subscribe(id string) (responseCh <-chan liteproto.TaskResponse, err error)

func (*PubSub) Unsubscribe

func (q *PubSub) Unsubscribe(id string) (err error)

type ResponderFactory

type ResponderFactory interface {
	Client() liteproto.Client
	MakeResponder(id, t string) liteproto.ResponderClient
}

ResponderFactory is a generator of ResponderClient objects.

type ResponsePub

type ResponsePub interface {
	Publish(response liteproto.TaskResponse) (err error)
}

ResponsePub is publisher part of response publisher/subscriber interface.

type ResponsePubSub

type ResponsePubSub interface {
	ResponsePub
	ResponseSub
}

ResponsePubSub is response publisher/subscriber interface.

type ResponseSub

type ResponseSub interface {
	Subscribe(id string) (responseData <-chan liteproto.TaskResponse, err error)
	Unsubscribe(id string) (err error)
}

ResponseSub is subscriber part of response publisher/subscriber interface.

type Runner

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

Runner is used to make a call to a remote server to execute a task. The call is made by an implementation of Caller interface. Responses are handled by an implementation of ResponseSub interface.

func NewRunner

func NewRunner(caller Caller, respSub ResponseSub) *Runner

NewRunner creates a new Runner.

func (*Runner) Run

func (rq *Runner) Run(ctx context.Context, r liteproto.TaskRequest, deadline time.Time) (<-chan liteproto.TaskResponse, chan<- struct{}, error)

Run method makes a call to a remote server. The response includes two channels, one for receiving a response (or potentially several responses) and a stop channel. The stop channel should be closed by the caller when no further responses are expected. If the function returns an error both channels will be nil.

type ServerFeeder

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

ServerFeeder is a helper object that handles requests for task execution and relays them to one of the registered task executors.

func NewServerFeeder

func NewServerFeeder(factory ResponderFactory, logger *log.Logger) (sf *ServerFeeder)

NewServerFeeder creates new ServerFeeder objects.

func (*ServerFeeder) Feed

func (sf *ServerFeeder) Feed(ctx context.Context, r liteproto.TaskRequest, deadline time.Time) error

Feed accepts requests for task execution. Parameter deadline should be zero time if it's not needed. This method implements Feeder interface.

func (*ServerFeeder) Register

func (sf *ServerFeeder) Register(typ string, execer liteproto.Execer)

Register assigns an liteproto.Execer to run tasks of a given type. This method is a part of liteproto.Server interface implementation.

func (*ServerFeeder) RegisterCatchAll

func (sf *ServerFeeder) RegisterCatchAll(execer liteproto.ExecerWithResponder)

RegisterCatchAll assigns an liteproto.ExecerWithResponder to run all tasks that are not already assigned to some other Execer. This method is a part of liteproto.Server interface implementation.

func (*ServerFeeder) RegisterWithResponder

func (sf *ServerFeeder) RegisterWithResponder(typ string, execer liteproto.ExecerWithResponder)

RegisterWithResponder assigns an liteproto.ExecerWithResponder to run tasks of a given type. This method is a part of liteproto.Server interface implementation.

Jump to

Keyboard shortcuts

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