Documentation
¶
Overview ¶
Package operatorclient connects an out-of-process operator to the engine's OperatorService: one Connect call registers one worker and returns the Session that streams its assigned actions, keeps its action set up to date and reports task progress. The package speaks to a *grpc.ClientConn the caller owns; pkg/client's Operator accessor builds one over its own connection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Connect(ctx context.Context, req *ConnectRequest) (Session, error)
}
Client connects an out-of-process operator to the engine's OperatorService. One Connect call is one live worker.
type CloseOpt ¶
type CloseOpt func(*closeOpts)
CloseOpt changes how a session is closed.
func WithDrainTimeout ¶
WithDrainTimeout bounds the wait for in-flight actions on Close. When it elapses the session hangs up with work still outstanding, which the engine retries once the task times out.
func WithoutDrain ¶
func WithoutDrain() CloseOpt
WithoutDrain closes the session at once, without pausing the worker or waiting for in-flight actions. Use it when the process is going away and the work it holds will be retried by the engine anyway.
type ConnectRequest ¶
type ConnectRequest struct {
// Name is the operator name, unique per tenant among GRPC operators. The
// engine upserts the operator row by this name.
Name string `validate:"required"`
// SlotConfig maps slot type to max units. The engine defaults it to
// {"default": 100} when empty.
SlotConfig map[string]int32
// Labels are worker labels for affinity assignment. Values follow the
// same conventions as GetActionListenerRequest.Labels (string or int).
Labels map[string]interface{}
// ResumeWorker controls whether a reconnect resumes the previous worker
// id. nil means true.
ResumeWorker *bool
}
ConnectRequest describes the operator and the worker backing the session. Workflows and actions are not part of registration: put workflows with Session.PutWorkflow and add actions with AddActions.
type Opt ¶
type Opt func(*opts)
Opt configures New.
func WithHeaders ¶
WithHeaders adds metadata to every RPC alongside the bearer token.
func WithLogger ¶
WithLogger sets the logger; the default discards everything.
func WithPresetWorkerLabels ¶
WithPresetWorkerLabels sets labels every connected worker carries on top of the request's own; a preset label wins over a request label of the same name.
func WithValidator ¶
WithValidator sets the validator Connect checks its request with.
type Registration ¶
type Registration struct {
TenantId string
OperatorId string
WorkerId string
// Resumed reports whether the most recent registration resumed the
// previous worker. It is false on the first connect.
Resumed bool
}
Registration is the identity the engine assigned to the current Listen stream. WorkerId can change across reconnects when the previous worker no longer exists or ResumeWorker is false.
type Session ¶
type Session interface {
// Actions starts the receive and heartbeat loops and returns the assigned
// action stream. The channels close when ctx is cancelled, the session is
// closed, or the stream fails permanently (reported on the error channel).
Actions(ctx context.Context) (<-chan *dispatchercontracts.AssignedAction, <-chan error, error)
// Registration returns the identity assigned by the most recent
// successful registration.
Registration() Registration
// SendStepActionEvent reports task progress. An empty WorkerId is filled
// from the current registration.
SendStepActionEvent(ctx context.Context, in *dispatchercontracts.StepActionEvent) (*dispatchercontracts.ActionEventResponse, error)
// PutWorkflow registers or updates a workflow through the admin service on
// the same connection and returns the action ids its tasks (including the
// on-failure task) run, normalized the way the engine stores them. It does
// not change the worker's action set: pass the ids to AddActions once the
// operator can run them.
PutWorkflow(ctx context.Context, wf *v1.CreateWorkflowVersionRequest) (*v1.CreateWorkflowVersionResponse, []string, error)
// AddActions queues action ids to add to the worker's action set. It
// never blocks: deltas are coalesced and sent in the background. Call
// Flush to wait for them to reach the engine.
AddActions(ids ...string)
// RemoveActions queues action ids to remove from the worker's action set.
// It never blocks; see AddActions.
RemoveActions(ids ...string)
// Flush waits until every queued delta has been acknowledged by the
// engine, which acknowledges a delta once it is committed to the worker's
// action set. A delta whose send failed and has not been retried yet is
// reported as the send error; it stays queued and is replayed by the next
// reconnect. The scheduler observes a committed change within about a
// second.
Flush(ctx context.Context) error
// OpenDurableTaskStream opens the OperatorService durable task stream
// with the session's operator metadata, shaped as the V1Dispatcher
// stream a durable task listener expects. The register message's worker
// id is rewritten to the current registration, so a listener built
// before a reconnect registers the worker the engine now knows. The
// caller owns the listener it builds over it and stops it before Close.
OpenDurableTaskStream(ctx context.Context) (v1.V1Dispatcher_DurableTaskClient, error)
// Pause stops the scheduler assigning to this session's worker. It sends
// the pause on the Listen stream and returns once the engine has
// acknowledged it, at which point nothing more is delivered on the stream:
// an action the scheduler had already assigned goes back to the queue. A
// caller that drains afterwards therefore holds the last actions it will
// get. The pause is stream state that the session restores on every
// reconnect until Resume.
Pause(ctx context.Context) error
// Resume lets the scheduler assign to the worker again, acknowledged the
// same way.
Resume(ctx context.Context) error
// Close pauses the worker, waits for the actions already handed to the
// consumer to be reported, flushes pending deltas with a short timeout,
// and ends the Listen stream, which deactivates the worker. Pass
// WithoutDrain to hang up at once instead.
Close(opts ...CloseOpt) error
}
Session is one registered operator worker. Actions may be called once; the other methods are safe to call concurrently until Close. The session reads its Listen stream from Connect on, so Flush observes delta acknowledgements whether or not Actions has been called.