worker

package
v2.3.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateInactive - no associated process
	StateInactive int64 = iota

	// StateReady - ready for job.
	StateReady

	// StateWorking - working on given payload.
	StateWorking

	// StateInvalid - indicates that WorkerProcess is being disabled and will be removed.
	StateInvalid

	// StateStopping - process is being softly stopped.
	StateStopping

	// StateKilling - process is being forcibly stopped
	StateKilling

	// StateDestroyed State of worker, when no need to allocate new one
	StateDestroyed

	// StateMaxJobsReached State of worker, when it reached executions limit
	StateMaxJobsReached

	// StateStopped - process has been terminated.
	StateStopped

	// StateErrored - error StateImpl (can't be used).
	StateErrored
)

SYNC WITH worker_watcher.GET

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator func() (SyncWorker, error)

Allocator is responsible for worker allocation in the pool

type BaseProcess

type BaseProcess interface {
	fmt.Stringer

	// Pid returns worker pid.
	Pid() int64

	// Created returns time worker was created at.
	Created() time.Time

	// State return receive-only WorkerProcess state object, state can be used to safely access
	// WorkerProcess status, time when status changed and number of WorkerProcess executions.
	State() State

	// Start used to run Cmd and immediately return
	Start() error

	// Wait must be called once for each WorkerProcess, call will be released once WorkerProcess is
	// complete and will return process error (if any), if stderr is presented it's value
	// will be wrapped as WorkerError. Method will return error code if php process fails
	// to find or Start the script.
	Wait() error

	// Stop sends soft termination command to the WorkerProcess and waits for process completion.
	Stop() error

	// Kill kills underlying process, make sure to call Wait() func to gather
	// error log from the stderr. Does not waits for process completion!
	Kill() error

	// Relay returns attached to worker goridge relay
	Relay() relay.Relay

	// AttachRelay used to attach goridge relay to the worker process
	AttachRelay(rl relay.Relay)
}

type Options

type Options func(p *Process)

func AddListeners

func AddListeners(listeners ...events.Listener) Options

type Process

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

Process - supervised process with api over goridge.Relay.

func InitBaseWorker

func InitBaseWorker(cmd *exec.Cmd, options ...Options) (*Process, error)

InitBaseWorker creates new Process over given exec.cmd.

func (*Process) AttachRelay

func (w *Process) AttachRelay(rl relay.Relay)

AttachRelay attaches relay to the worker

func (*Process) Created

func (w *Process) Created() time.Time

Created returns time worker was created at.

func (*Process) Kill

func (w *Process) Kill() error

Kill kills underlying process, make sure to call Wait() func to gather error log from the stderr. Does not waits for process completion!

func (*Process) Pid

func (w *Process) Pid() int64

Pid returns worker pid.

func (*Process) Relay

func (w *Process) Relay() relay.Relay

Relay returns relay attached to the worker

func (*Process) Start

func (w *Process) Start() error

func (*Process) State

func (w *Process) State() State

State return receive-only Process state object, state can be used to safely access Process status, time when status changed and number of Process executions.

func (*Process) Stop

func (w *Process) Stop() error

Stop sends soft termination command to the Process and waits for process completion.

func (*Process) String

func (w *Process) String() string

String returns Process description. fmt.Stringer interface

func (*Process) Wait

func (w *Process) Wait() error

Wait must be called once for each Process, call will be released once Process is complete and will return process error (if any), if stderr is presented it's value will be wrapped as WorkerError. Method will return error code if php process fails to find or Start the script.

func (*Process) Write

func (w *Process) Write(p []byte) (n int, err error)

Worker stderr

type State

type State interface {
	fmt.Stringer
	// Value returns StateImpl value
	Value() int64
	// Set sets the StateImpl
	Set(value int64)
	// NumExecs shows how many times WorkerProcess was invoked
	NumExecs() uint64
	// IsActive returns true if WorkerProcess not Inactive or Stopped
	IsActive() bool
	// RegisterExec using to registering php executions
	RegisterExec()
	// SetLastUsed sets worker last used time
	SetLastUsed(lu uint64)
	// LastUsed return worker last used time
	LastUsed() uint64
}

State represents WorkerProcess status and updated time.

type StateImpl

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

func NewWorkerState

func NewWorkerState(value int64) *StateImpl

Thread safe

func (*StateImpl) IsActive

func (s *StateImpl) IsActive() bool

IsActive returns true if WorkerProcess not Inactive or Stopped

func (*StateImpl) LastUsed

func (s *StateImpl) LastUsed() uint64

func (*StateImpl) NumExecs

func (s *StateImpl) NumExecs() uint64

NumExecs returns number of registered WorkerProcess execs.

func (*StateImpl) RegisterExec

func (s *StateImpl) RegisterExec()

RegisterExec register new execution atomically

func (*StateImpl) Set

func (s *StateImpl) Set(value int64)

Set change StateImpl value (status)

func (*StateImpl) SetLastUsed

func (s *StateImpl) SetLastUsed(lu uint64)

SetLastUsed Update last used time

func (*StateImpl) String

func (s *StateImpl) String() string

String returns current StateImpl as string.

func (*StateImpl) Value

func (s *StateImpl) Value() int64

Value StateImpl returns StateImpl value

type SyncWorker

type SyncWorker interface {
	// BaseProcess provides basic functionality for the SyncWorker
	BaseProcess
	// Exec used to execute payload on the SyncWorker, there is no TIMEOUTS
	Exec(rqs payload.Payload) (payload.Payload, error)
	// ExecWithTTL used to handle Exec with TTL
	ExecWithTTL(ctx context.Context, p payload.Payload) (payload.Payload, error)
}

func From

func From(process *Process) SyncWorker

From creates SyncWorker from BaseProcess

type SyncWorkerImpl

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

func (*SyncWorkerImpl) AttachRelay

func (tw *SyncWorkerImpl) AttachRelay(rl relay.Relay)

func (*SyncWorkerImpl) Created

func (tw *SyncWorkerImpl) Created() time.Time

func (*SyncWorkerImpl) Exec

Exec payload without TTL timeout.

func (*SyncWorkerImpl) ExecWithTTL

func (tw *SyncWorkerImpl) ExecWithTTL(ctx context.Context, p payload.Payload) (payload.Payload, error)

Exec payload without TTL timeout.

func (*SyncWorkerImpl) Kill

func (tw *SyncWorkerImpl) Kill() error

func (*SyncWorkerImpl) Pid

func (tw *SyncWorkerImpl) Pid() int64

func (*SyncWorkerImpl) Relay

func (tw *SyncWorkerImpl) Relay() relay.Relay

func (*SyncWorkerImpl) Start

func (tw *SyncWorkerImpl) Start() error

func (*SyncWorkerImpl) State

func (tw *SyncWorkerImpl) State() State

func (*SyncWorkerImpl) Stop

func (tw *SyncWorkerImpl) Stop() error

func (*SyncWorkerImpl) String

func (tw *SyncWorkerImpl) String() string

func (*SyncWorkerImpl) Wait

func (tw *SyncWorkerImpl) Wait() error

Jump to

Keyboard shortcuts

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