batch

package
v0.0.0-...-5fe9b4e Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package batch provides persistence for OpenAI-compatible batch lifecycle endpoints.

Index

Constants

View Source
const (
	// RequestIDMetadataKey is the legacy metadata key used to persist batch request IDs.
	RequestIDMetadataKey = "request_id"
	// UsageLoggedAtMetadataKey is the legacy metadata key used to mark logged batch usage.
	UsageLoggedAtMetadataKey = "usage_logged_at"
)

Variables

View Source
var ErrNotFound = errors.New("batch not found")

ErrNotFound indicates a requested batch was not found.

Functions

This section is empty.

Types

type MemoryStore

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

MemoryStore keeps batches in process memory. Data survives across requests but not process restarts.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates an empty in-memory batch store.

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close releases resources (no-op for memory store).

func (*MemoryStore) Create

func (s *MemoryStore) Create(_ context.Context, batch *StoredBatch) error

Create stores a new batch.

func (*MemoryStore) Get

func (s *MemoryStore) Get(_ context.Context, id string) (*StoredBatch, error)

Get retrieves one batch by id.

func (*MemoryStore) List

func (s *MemoryStore) List(_ context.Context, limit int, after string) ([]*StoredBatch, error)

List returns batches ordered by created_at desc, id desc.

func (*MemoryStore) Update

func (s *MemoryStore) Update(_ context.Context, batch *StoredBatch) error

Update replaces an existing batch object.

type MongoDBStore

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

MongoDBStore stores batches in MongoDB.

func NewMongoDBStore

func NewMongoDBStore(database *mongo.Database) (*MongoDBStore, error)

NewMongoDBStore creates collection indexes if needed.

func (*MongoDBStore) Close

func (s *MongoDBStore) Close() error

Close is a no-op; Mongo client lifecycle is managed by storage layer.

func (*MongoDBStore) Create

func (s *MongoDBStore) Create(ctx context.Context, batch *StoredBatch) error

Create inserts a new batch.

func (*MongoDBStore) Get

func (s *MongoDBStore) Get(ctx context.Context, id string) (*StoredBatch, error)

Get returns a batch by id.

func (*MongoDBStore) List

func (s *MongoDBStore) List(ctx context.Context, limit int, after string) ([]*StoredBatch, error)

List returns batches ordered by created_at desc, id desc.

func (*MongoDBStore) Update

func (s *MongoDBStore) Update(ctx context.Context, batch *StoredBatch) error

Update updates a stored batch object.

type PostgreSQLStore

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

PostgreSQLStore stores batches in PostgreSQL.

func NewPostgreSQLStore

func NewPostgreSQLStore(ctx context.Context, pool *pgxpool.Pool) (*PostgreSQLStore, error)

NewPostgreSQLStore creates the batches table and indexes if needed.

func (*PostgreSQLStore) Close

func (s *PostgreSQLStore) Close() error

Close is a no-op; pool lifecycle is managed by storage layer.

func (*PostgreSQLStore) Create

func (s *PostgreSQLStore) Create(ctx context.Context, batch *StoredBatch) error

Create inserts a new batch.

func (*PostgreSQLStore) Get

func (s *PostgreSQLStore) Get(ctx context.Context, id string) (*StoredBatch, error)

Get returns a batch by id.

func (*PostgreSQLStore) List

func (s *PostgreSQLStore) List(ctx context.Context, limit int, after string) ([]*StoredBatch, error)

List returns batches ordered by created_at desc, id desc.

func (*PostgreSQLStore) Update

func (s *PostgreSQLStore) Update(ctx context.Context, batch *StoredBatch) error

Update updates a stored batch object.

type Result

type Result struct {
	Store   Store
	Storage storage.Storage
}

Result holds the initialized batch store and optional owned storage.

func New

func New(ctx context.Context, cfg *config.Config) (*Result, error)

New creates a batch store from app configuration.

func NewWithSharedStorage

func NewWithSharedStorage(ctx context.Context, shared storage.Storage) (*Result, error)

NewWithSharedStorage creates a batch store using a shared storage connection.

func (*Result) Close

func (r *Result) Close() error

Close releases resources held by the batch store.

type SQLiteStore

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

SQLiteStore stores batches in SQLite.

func NewSQLiteStore

func NewSQLiteStore(db *sql.DB) (*SQLiteStore, error)

NewSQLiteStore creates the batches table and indexes if needed.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close is a no-op; DB lifecycle is managed by storage layer.

func (*SQLiteStore) Create

func (s *SQLiteStore) Create(ctx context.Context, batch *StoredBatch) error

Create inserts a new batch.

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, id string) (*StoredBatch, error)

Get returns a batch by id.

func (*SQLiteStore) List

func (s *SQLiteStore) List(ctx context.Context, limit int, after string) ([]*StoredBatch, error)

List returns batches ordered by created_at desc, id desc.

func (*SQLiteStore) Update

func (s *SQLiteStore) Update(ctx context.Context, batch *StoredBatch) error

Update updates a stored batch object.

type Store

type Store interface {
	Create(ctx context.Context, batch *StoredBatch) error
	Get(ctx context.Context, id string) (*StoredBatch, error)
	List(ctx context.Context, limit int, after string) ([]*StoredBatch, error)
	Update(ctx context.Context, batch *StoredBatch) error
	Close() error
}

Store defines persistence operations for batch lifecycle APIs.

type StoredBatch

type StoredBatch struct {
	Batch                     *core.BatchResponse `json:"batch"`
	RequestEndpointByCustomID map[string]string   `json:"request_endpoint_by_custom_id,omitempty"`
	OriginalInputFileID       string              `json:"original_input_file_id,omitempty"`
	RewrittenInputFileID      string              `json:"rewritten_input_file_id,omitempty"`
	RequestID                 string              `json:"request_id,omitempty"`
	UserPath                  string              `json:"user_path,omitempty"`
	WorkflowVersionID         string              `json:"workflow_version_id,omitempty"`
	UsageEnabled              *bool               `json:"usage_enabled,omitempty"`
	UsageLoggedAt             *time.Time          `json:"usage_logged_at,omitempty"`
}

StoredBatch keeps the public batch response separate from gateway-only persistence hints that should never be exposed by API DTOs.

func (*StoredBatch) EffectiveUsageEnabled

func (s *StoredBatch) EffectiveUsageEnabled() bool

EffectiveUsageEnabled reports whether batch usage logging should run. Nil means the value was not persisted by older versions, so usage remains enabled.

Jump to

Keyboard shortcuts

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