runtime

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCheckpointNotFound = errors.New("checkpoint not found")

ErrCheckpointNotFound marks a missing checkpoint.

Functions

func DialGRPC

func DialGRPC(endpoint string) (*grpc.ClientConn, error)

DialGRPC opens a Memory Service gRPC connection.

func DialGRPCWithConfig added in v0.3.0

func DialGRPCWithConfig(endpoint string, cfg GRPCDialConfig) (*grpc.ClientConn, error)

Types

type BackgroundErrorSource added in v0.3.0

type BackgroundErrorSource interface {
	BackgroundErrors() <-chan error
}

BackgroundErrorSource reports terminal asynchronous failures that must stop processing before any more events or checkpoints are committed.

type BootstrapProcessor added in v0.3.0

type BootstrapProcessor interface {
	Bootstrap(ctx context.Context, events EventClient, save func(context.Context) error) (afterCursor string, err error)
}

BootstrapProcessor performs a restartable current-state scan after the checkpoint lease is acquired and before live replay begins. save persists the processor's current scan token using the active lease.

type Checkpoint

type Checkpoint struct {
	ClientID    string
	ContentType string
	Value       json.RawMessage
	Revision    string
	UpdatedAt   time.Time
}

Checkpoint is a stored processor checkpoint.

type CheckpointClient

type CheckpointClient interface {
	Get(ctx context.Context, clientID string) (Checkpoint, error)
	Put(ctx context.Context, clientID, contentType string, value json.RawMessage) (Checkpoint, error)
}

CheckpointClient persists one processor checkpoint.

type CheckpointLease added in v0.3.0

type CheckpointLease struct {
	Token      string
	Generation uint64
	ExpiresAt  time.Time
}

type Config

type Config struct {
	ClientID           string
	Kinds              []string
	EntryChannels      []string
	EntryContentTypes  []string
	EntryRoles         []string
	Scope              string
	AfterCursor        string
	Justification      string
	Detail             string
	CheckpointInterval time.Duration
	ReconnectMin       time.Duration
	ReconnectMax       time.Duration
	LeaseTTL           time.Duration
	OnReady            func(bool)
}

Config controls the shared checkpointed stream loop.

type EventClient

type EventClient interface {
	Subscribe(ctx context.Context, req SubscribeRequest) (EventStream, error)
}

EventClient subscribes to Memory Service events.

type EventEnvelope

type EventEnvelope struct {
	Event  string
	Kind   string
	Change string
	Data   json.RawMessage
	Cursor string
	Time   time.Time
}

EventEnvelope is the normalized event shape consumed by processors.

type EventProcessor

type EventProcessor interface {
	ContentType() string
	Load(state json.RawMessage) error
	Handle(ctx context.Context, event EventEnvelope) error
	Snapshot() (json.RawMessage, error)
	Flush(ctx context.Context) error
}

EventProcessor handles events and exposes a small durable checkpoint payload.

type EventStream

type EventStream interface {
	Recv() (EventEnvelope, error)
}

EventStream opens a durable event stream.

type GRPCAuth

type GRPCAuth struct {
	APIKey      string
	BearerToken string
	ClientID    string
}

GRPCAuth configures Memory Service gRPC request metadata.

type GRPCCheckpointClient

type GRPCCheckpointClient struct {
	Client pb.AdminCheckpointServiceClient
	Auth   GRPCAuth
}

GRPCCheckpointClient adapts AdminCheckpointService to CheckpointClient.

func (GRPCCheckpointClient) AcquireLease added in v0.3.0

func (c GRPCCheckpointClient) AcquireLease(ctx context.Context, clientID string, ttl time.Duration) (CheckpointLease, error)

func (GRPCCheckpointClient) Get

func (c GRPCCheckpointClient) Get(ctx context.Context, clientID string) (Checkpoint, error)

Get loads a checkpoint.

func (GRPCCheckpointClient) Put

func (c GRPCCheckpointClient) Put(ctx context.Context, clientID, contentType string, value json.RawMessage) (Checkpoint, error)

Put stores a checkpoint.

func (GRPCCheckpointClient) PutCAS added in v0.3.0

func (c GRPCCheckpointClient) PutCAS(ctx context.Context, clientID, contentType string, value json.RawMessage, expectedRevision, leaseToken string) (Checkpoint, error)

func (GRPCCheckpointClient) ReleaseLease added in v0.3.0

func (c GRPCCheckpointClient) ReleaseLease(ctx context.Context, clientID, leaseToken string) error

func (GRPCCheckpointClient) RenewLease added in v0.3.0

func (c GRPCCheckpointClient) RenewLease(ctx context.Context, clientID, leaseToken string, ttl time.Duration) (CheckpointLease, error)

type GRPCDialConfig added in v0.3.0

type GRPCDialConfig struct {
	TLS           bool
	CAFile        string
	AllowInsecure bool
	// MaxReceiveBytes raises the default receive allowance when a processor
	// accepts individual records larger than the service default.
	MaxReceiveBytes int
}

GRPCDialConfig applies the processor transport policy. Remote plaintext is rejected unless the caller explicitly marks the connection as development-only.

type GRPCEventClient

type GRPCEventClient struct {
	Client pb.EventStreamServiceClient
	Auth   GRPCAuth
}

GRPCEventClient adapts EventStreamService to EventClient.

func (GRPCEventClient) Subscribe

Subscribe opens a gRPC event stream.

type LeaseGenerationConsumer added in v0.3.0

type LeaseGenerationConsumer interface {
	SetLeaseGeneration(generation uint64) error
}

LeaseGenerationConsumer receives the fencing generation before event processing starts.

type LeasedCheckpointClient added in v0.3.0

type LeasedCheckpointClient interface {
	CheckpointClient
	PutCAS(ctx context.Context, clientID, contentType string, value json.RawMessage, expectedRevision, leaseToken string) (Checkpoint, error)
	AcquireLease(ctx context.Context, clientID string, ttl time.Duration) (CheckpointLease, error)
	RenewLease(ctx context.Context, clientID, leaseToken string, ttl time.Duration) (CheckpointLease, error)
	ReleaseLease(ctx context.Context, clientID, leaseToken string) error
}

LeasedCheckpointClient adds compare-and-swap ownership for processors that require one active replica per checkpoint.

type Runtime

type Runtime struct {
	Events      EventClient
	Checkpoints CheckpointClient
	Processor   EventProcessor
	Config      Config
	// contains filtered or unexported fields
}

Runtime runs an EventProcessor against a checkpointed event stream.

func (*Runtime) Run

func (r *Runtime) Run(ctx context.Context) error

Run loads checkpoint state, subscribes to events, dispatches them to the processor, and persists checkpoint snapshots after safe progress.

type SubscribeRequest

type SubscribeRequest struct {
	Kinds             []string
	Detail            string
	AfterCursor       string
	Scope             string
	Justification     string
	EntryChannels     []string
	EntryContentTypes []string
	EntryRoles        []string
	InitialState      string
}

SubscribeRequest is the runtime's transport-independent event request.

Jump to

Keyboard shortcuts

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