workers

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeCostUSD

func ComputeCostUSD(promptTokens, completionTokens int64, inputPerMTok, outputPerMTok float64) *float64

ComputeCostUSD returns USD cost from per-million-token prices, or nil if prices are missing or there is no token usage to price.

func EncodeUsage

func EncodeUsage(e usage.Event) ([]byte, error)

func IngestPayload added in v0.3.0

func IngestPayload(ctx context.Context, sink UsageSink, prices PriceLookup, payload []byte) error

IngestPayload decodes one usage outbox payload and writes usage_events immediately (no worker drain). Used for spoke HTTP ingest and optional sync postgres backends.

func ProcessOnce

func ProcessOnce(ctx context.Context, src OutboxSource, sink UsageSink, prices PriceLookup, metrics ...*telemetry.WorkerMetrics) (int, error)

ProcessOnce claims pending outbox rows and writes usage_events. Optional metrics argument records worker counters when non-nil.

func ProcessPlatformEventsOnce

func ProcessPlatformEventsOnce(ctx context.Context, src OutboxSource, pub EventPublisher, metrics ...*telemetry.WorkerMetrics) (int, error)

ProcessPlatformEventsOnce claims pending platform_event_outbox rows and publishes them.

Types

type EventPublisher

type EventPublisher interface {
	Publish(ctx context.Context, e platform.Event) error
}

EventPublisher delivers a platform domain event to an external broker.

type OutboxRow

type OutboxRow struct {
	ID          int64
	Payload     []byte
	ProcessedAt *time.Time
}

type OutboxSource

type OutboxSource interface {
	ClaimBatch(ctx context.Context, limit int) ([]OutboxRow, error)
	MarkProcessed(ctx context.Context, id int64) error
}

type PriceLookup

type PriceLookup interface {
	LookupModelPrice(ctx context.Context, providerType, model string) (inputPerMTok, outputPerMTok float64, ok bool, err error)
}

type UsageEnqueuer

type UsageEnqueuer interface {
	Enqueue(ctx context.Context, payload []byte) error
}

UsageEnqueuer is the gateway write-side port for usage_outbox.

type UsagePayload

type UsagePayload = usage.Event

UsagePayload is an alias for the canonical usage.Event carried in the outbox.

type UsageSink

type UsageSink interface {
	InsertUsage(ctx context.Context, e usage.Event, costUSD *float64) error
}

Jump to

Keyboard shortcuts

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