package node

Import Path
	/pkg/node (on go.dev)

Dependency Relation
	imports 21 packages, and imported by one package

Involved Source Files Package node provides distributed worker pools with supervisors. node_client.go node_worker.go supervisor.go supervisor_misc.go
Package-Level Type Names (total 9)
/* sort by: | */
A is a struct for node arguments. It's a typesafe alternative to [am.A]. BootAddr is the local address of the Bootstrap machine. Bootstrap is the RPC machine used to connect WorkerRpc to the Supervisor. Dispose the worker. Id is a machine ID. LocalAddr is the public address of a Supervisor or WorkerRpc. NodesList is a list of available nodes (supervisors' public RPC addresses). PublicAddr is the public address of a Supervisor or WorkerRpc. SuperRpcId is a machine ID of the super RPC client. WorkerAddr is an index for WorkerInfo. WorkerInfo describes a worker. WorkerRpc is the RPC client connected to a WorkerRpc. WorkerRpcId is a machine ID of the worker RPC client. WorkerState is a requested state of workers, eg for listings. WorkersCh returns a list of workers. This channel has to be buffered. func ParseArgs(args am.A) *A func Pass(args *A) am.A func PassRpc(args *A) am.A
ARpc is a subset of A, that can be passed over RPC. BootAddr is the local address of the Bootstrap machine. Id is a machine ID. LocalAddr is the public address of a Supervisor, Worker, or [bootstrap]. NodesList is a list of available nodes (supervisors' public RPC addresses). PublicAddr is the public address of a Supervisor or Worker. SuperRpcId is a machine ID of the super RPC client. WorkerRpcId is a machine ID of the worker RPC client.
Client is a node client, connecting to a supervisor and then a worker. ConnTimeout is the time to wait for an outbound connection to be established. Default is 5 seconds. ExceptionHandler *am.ExceptionHandler LeaveSuper is a flag to leave the supervisor after connecting to the worker. TODO LogEnabled bool Mach *am.Machine Name string RpcSuper *rpc.Client RpcWorker *rpc.Client SuperAddr string Dispose deallocates resources and stops the client's RPC connections. ExceptionState is a final entry handler for the StateException state. Args: - err error: The error that caused the StateException state. - panic *ExceptionArgsPanic: Optional details about the panic. ReqWorker sends a request to add a "WorkerRequested" state to the client's state machine and waits for "WorkerReady" state. Start initializes the client with a list of node addresses to connect to. (*Client) StartEnd(e *am.Event) (*Client) StartEnter(e *am.Event) bool (*Client) StartState(e *am.Event) Stop halts the client's connection to both the supervisor and worker RPCs, and removes the client state from the state machine. (*Client) WorkerPayloadEnter(e *am.Event) bool WorkerPayloadState handles both Supervisor and Worker inbound payloads, but this shared code only deals with [states.ClientStatesDef.WorkerRequested]. (*Client) WorkerRequestedEnter(e *am.Event) bool (*Client) WorkerRequestedState(e *am.Event) *Client : github.com/pancsta/asyncmachine-go/pkg/rpc/states.ConsumerHandlers func NewClient(ctx context.Context, clientId string, workerKind string, workerSchema am.Schema, opts *ClientOpts) (*Client, error)
ClientOpts provides configuration options for creating a new client state machine. Optional schema for the client. Should extend [states.ClientStatesDef]. Optional state names for ClientSchema. Parent is a parent state machine for a new client state machine. See [am.Opts]. Tags []string func NewClient(ctx context.Context, clientId string, workerKind string, workerSchema am.Schema, opts *ClientOpts) (*Client, error)
ClientSendPayloadState am.HandlerFinal ConnTimeout is the time to wait for an outbound connection to be established. Default is 5s. DeliveryTimeout is a timeout for RPC delivery. ExceptionHandler *am.ExceptionHandler HealthcheckPause is the time between trying to get a Healtcheck response from a worker. HealthcheckState am.HandlerFinal Heartbeat is the frequency of the Heartbeat state, which normalized the pool and checks workers. Default 1m. KillWorkerState am.HandlerFinal LocalAddr is the address for the local RPC server to listen on. The effective address is at [LocalRpc.Addr]. LocalRpc is the local RPC server, used by other supervisors to connect. TODO rpc/mux LogEnabled bool Mach *am.Machine Max is the maximum number of workers. Default is 10. MaxClientWorkers is the maximum number of workers per 1 client. Defaults to Max. Min is the minimum number of workers. Default is 2. Name is the name of the supervisor. OpTimeout is the default timeout for operations (eg getters). PoolPause is the time to wait between normalizing the pool. Default is 5s. PublicAddr is the address for the public RPC server to listen on. The effective address is at [PublicMux.Addr]. PublicMux is the public listener to create RPC servers for each client. PublicRpc are the public RPC servers of connected clients, indexed by remote addresses. SuperSendPayloadState am.HandlerFinal TestFork func(string) error TestKill func(string) error Warm is the number of warm (ready) workers. Default is 5. WorkerBin is the path and args to the worker binary. WorkerCheckInterval defines how often to pull a worker's state. Default 1s. WorkerErrKill is the number of errors to kill a worker. Default is 3. WorkerErrRecent is the time to consider recent errors. Default is 1m. WorkerErrTtl is the time to keep worker errors in memory. Default is 10m. WorkerGoneState am.HandlerFinal WorkerKind is the kind of worker this supervisor is managing. WorkerReadyState am.HandlerFinal CheckPool tries to set pool as ready and normalizes it, if not. (*Supervisor) ClientConnectedState(e *am.Event) (*Supervisor) ClientDisconnectedEnter(e *am.Event) bool (*Supervisor) ClientDisconnectedState(e *am.Event) (*Supervisor) Dispose() (*Supervisor) ErrWorkerState(e *am.Event) ExceptionState is a final entry handler for the StateException state. Args: - err error: The error that caused the StateException state. - panic *ExceptionArgsPanic: Optional details about the panic. (*Supervisor) ForkWorkerEnter(e *am.Event) bool (*Supervisor) ForkWorkerState(e *am.Event) (*Supervisor) ForkingWorkerEnter(e *am.Event) bool (*Supervisor) ForkingWorkerState(e *am.Event) (*Supervisor) HeartbeatState(e *am.Event) (*Supervisor) KillingWorkerEnter(e *am.Event) bool (*Supervisor) KillingWorkerState(e *am.Event) (*Supervisor) ListWorkersEnter(e *am.Event) bool (*Supervisor) ListWorkersState(e *am.Event) (*Supervisor) NormalizingPoolState(e *am.Event) (*Supervisor) PoolReadyEnter(e *am.Event) bool (*Supervisor) PoolReadyExit(e *am.Event) bool (*Supervisor) ProvideWorkerEnter(e *am.Event) bool (*Supervisor) ProvideWorkerState(e *am.Event) SetPool sets the pool parameters with defaults. (*Supervisor) SetWorkerEnter(e *am.Event) bool (*Supervisor) SetWorkerState(e *am.Event) (*Supervisor) Start(publicAddr string) (*Supervisor) StartEnd(e *am.Event) (*Supervisor) StartEnter(e *am.Event) bool (*Supervisor) StartState(e *am.Event) (*Supervisor) Stop() (*Supervisor) WorkerConnectedEnter(e *am.Event) bool (*Supervisor) WorkerConnectedState(e *am.Event) (*Supervisor) WorkerForkedEnter(e *am.Event) bool (*Supervisor) WorkerForkedState(e *am.Event) (*Supervisor) WorkerKilledEnter(e *am.Event) bool (*Supervisor) WorkerKilledState(e *am.Event) Workers returns a list of workers in a desired state. If [ctx] expires, it will reutrn nil, nil. func NewSupervisor(ctx context.Context, workerKind string, workerBin []string, workerSchema am.Schema, opts *SupervisorOpts) (*Supervisor, error)
InstanceNum is the number of this instance in a failsafe config, used for the ID. Parent is a parent state machine for a new Supervisor state machine. See [am.Opts]. TODO func NewSupervisor(ctx context.Context, workerKind string, workerBin []string, workerSchema am.Schema, opts *SupervisorOpts) (*Supervisor, error)
AcceptClient is the ID of a client, passed by the supervisor. Worker should only accept connections from this client. BootAddr is the address of the bootstrap machine. BootRpc is the RPC client connection to bootstrap machine, which passes connection info to the Supervisor. ConnTimeout is the time to wait for an outbound connection to be established. DeliveryTimeout time.Duration ExceptionHandler *am.ExceptionHandler Kind string LocalAddr is the address of the local RPC server. LocalRpc is the local RPC server, used by the Supervisor to connect. Mach *am.Machine Name string PublicAddr is the address of the public RPC server. PublicRpc is the public RPC server, used by the Client to connect. (*Worker) ErrNetworkState(e *am.Event) ExceptionState is a final entry handler for the StateException state. Args: - err error: The error that caused the StateException state. - panic *ExceptionArgsPanic: Optional details about the panic. (*Worker) HealthcheckState(e *am.Event) (*Worker) LocalRpcReadyState(e *am.Event) (*Worker) PublicRpcReadyState(e *am.Event) (*Worker) RpcReadyState(e *am.Event) (*Worker) SendPayloadEnter(e *am.Event) bool (*Worker) ServeClientEnter(e *am.Event) bool (*Worker) ServeClientState(e *am.Event) Start connects the worker to the bootstrap RPC. (*Worker) StartEnd(e *am.Event) (*Worker) StartEnter(e *am.Event) bool (*Worker) StartState(e *am.Event) Stop halts the worker's state machine and optionally disposes of its resources based on the dispose flag. func NewWorker(ctx context.Context, kind string, workerStruct am.Schema, stateNames am.S, opts *WorkerOpts) (*Worker, error)
Parent is a parent state machine for a new Worker state machine. See [am.Opts]. TODO func NewWorker(ctx context.Context, kind string, workerStruct am.Schema, stateNames am.S, opts *WorkerOpts) (*Worker, error)
states of a worker func (*Supervisor).Workers(ctx context.Context, state WorkerState) ([]*workerInfo, error) const StateBusy const StateIdle const StateIniting const StateReady const StateRpc
Package-Level Functions (total 14)
AddErrPool wraps an error in the ErrPool sentinel and adds to a machine. TODO add event param
AddErrPoolStr wraps a msg in the ErrPool sentinel and adds to a machine. TODO add event param
AddErrRpc wraps an error in the ErrRpc sentinel and adds to a machine. TODO add event param
AddErrWorker wraps an error in the ErrWorker sentinel and adds to a machine.
AddErrWorkerStr wraps a msg in the ErrWorker sentinel and adds to a machine. TODO add event param
GetSuperClientId returns a Node Supervisor machine ID from a name.
GetWorkerClientId returns a Node Client machine ID from a name.
LogArgs is an args logger for A and [rpc.A].
NewClient creates a new Client instance with the provided context, id, workerKind, state dependencies, and options. Returns a pointer to the Client instance and an error if any validation or initialization fails. workerKind: any string used to build IDs and address workers
NewSupervisor initializes and returns a new Supervisor instance with specified context, worker attributes, and options. workerBin: path to run the worker binary file (for [exec.CommandContext]).
NewWorker initializes a new Worker instance and returns it, or an error if validation fails.
ParseArgs extracts A from [am.Event.Args][APrefix].
Pass prepares [am.A] from A to pass to further mutations.
PassRpc prepares [am.A] from A to pass over RPC.
Package-Level Constants (total 8)
const APrefix = "am_node"
EnvAmNodeLogClient enables extra logging for node client.
EnvAmNodeLogSupervisor enables extra logging for node supervisor.
const StateBusy WorkerState = "busy"
const StateIdle WorkerState = "idle"
const StateIniting WorkerState = "initing"
const StateReady WorkerState = "ready"
const StateRpc WorkerState = "rpc"