dispatch

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPollInterval = 1 * time.Second

DefaultPollInterval how often the dispatcher polls for dispatchable packets.

Variables

View Source
var ErrTransferAlreadyInPipeline = errors.New("transfer already in pipeline")

ErrTransferAlreadyInPipeline the transfer is already being relayed.

Functions

This section is empty.

Types

type Deduper

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

Deduper rejects transfers already in flight in the wrapped pipeline. It consumes the pipeline's output itself to learn when transfers leave. A transfer that left stays rejected until Release: a packet read before it left may predate its last writes.

func NewDeduper

func NewDeduper(pl pipeline.TransferPipeline) *Deduper

func (*Deduper) Close

func (d *Deduper) Close()

func (*Deduper) Poll

func (d *Deduper) Poll() (*processors.Transfer, error)

Poll is a noop: the deduper drains the wrapped pipeline itself.

func (*Deduper) Push

func (d *Deduper) Push(ctx context.Context, tr *processors.Transfer) bool

func (*Deduper) Release

func (d *Deduper) Release()

Release lets the transfers that have left the pipeline be pushed again. Call it before reading the packets to push.

type DispatcherStorage

type DispatcherStorage interface {
	ListDispatchablePackets(ctx context.Context) ([]store.Packet, error)
	UpdatePacketStatus(ctx context.Context, key store.PacketKey, status store.RelayStatus) error
}

DispatcherStorage the persistence used by the dispatcher.

type PipelineSet

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

PipelineSet creates and caches one pipeline per route.

func NewPipelineSet

func NewPipelineSet(logger *slog.Logger, cfg config.Config, deps pipeline.Deps) *PipelineSet

func (*PipelineSet) Close

func (s *PipelineSet) Close()

Close closes every pipeline. The context the pipelines were created with must already be canceled: pipeline outputs only close on cancellation.

func (*PipelineSet) Pipeline

Pipeline returns the pipeline for the transfer's route, creating it on first use. Transfers whose source client has no configured route error.

func (*PipelineSet) Release

func (s *PipelineSet) Release()

func (*PipelineSet) Routes

func (s *PipelineSet) Routes() []processors.Route

Routes returns every configured relay route, in both directions.

type Pipelines

type Pipelines interface {
	Pipeline(ctx context.Context, tr *processors.Transfer) (pipeline.TransferPipeline, error)
	// Release lets the transfers that have left their pipelines be pushed
	// again.
	Release()
	Routes() []processors.Route
	Close()
}

Pipelines identifies the pipeline a transfer is relayed through.

type RelayDispatcher

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

RelayDispatcher polls the store for dispatchable packets and routes them to their pipelines. The relay API couples to the dispatcher through the store: it inserts packets, the dispatcher picks them up on the next poll.

func NewRelayDispatcher

func NewRelayDispatcher(
	storage DispatcherStorage,
	pipelines Pipelines,
	pollInterval time.Duration,
	logger *slog.Logger,
) *RelayDispatcher

func (*RelayDispatcher) Start

func (d *RelayDispatcher) Start() error

Start begins the dispatch loop in its own goroutine. Polls for dispatchable packets until Stop is called.

func (*RelayDispatcher) Stop

func (d *RelayDispatcher) Stop() error

Stop cancels the dispatch loop and blocks until it has exited and every pipeline it created is closed.

func (*RelayDispatcher) SubmitTransfer

func (d *RelayDispatcher) SubmitTransfer(ctx context.Context, tr *processors.Transfer) error

SubmitTransfer routes the transfer to its pipeline and pushes it.

func (*RelayDispatcher) SubmitWaitingDispatchablePackets

func (d *RelayDispatcher) SubmitWaitingDispatchablePackets(ctx context.Context) error

SubmitWaitingDispatchablePackets pushes every selected non-terminal packet into its pipeline. Packets that fail to submit for anything other than already being in flight are marked failed: submission only fails on configuration errors that will not resolve by retrying.

Jump to

Keyboard shortcuts

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