Documentation
¶
Overview ¶
Package batch provides persistence for OpenAI-compatible batch lifecycle endpoints.
Index ¶
- Constants
- Variables
- type MemoryStore
- func (s *MemoryStore) Close() error
- func (s *MemoryStore) Create(_ context.Context, batch *StoredBatch) error
- func (s *MemoryStore) Get(_ context.Context, id string) (*StoredBatch, error)
- func (s *MemoryStore) List(_ context.Context, limit int, after string) ([]*StoredBatch, error)
- func (s *MemoryStore) Update(_ context.Context, batch *StoredBatch) error
- type MongoDBStore
- func (s *MongoDBStore) Close() error
- func (s *MongoDBStore) Create(ctx context.Context, batch *StoredBatch) error
- func (s *MongoDBStore) Get(ctx context.Context, id string) (*StoredBatch, error)
- func (s *MongoDBStore) List(ctx context.Context, limit int, after string) ([]*StoredBatch, error)
- func (s *MongoDBStore) Update(ctx context.Context, batch *StoredBatch) error
- type PostgreSQLStore
- func (s *PostgreSQLStore) Close() error
- func (s *PostgreSQLStore) Create(ctx context.Context, batch *StoredBatch) error
- func (s *PostgreSQLStore) Get(ctx context.Context, id string) (*StoredBatch, error)
- func (s *PostgreSQLStore) List(ctx context.Context, limit int, after string) ([]*StoredBatch, error)
- func (s *PostgreSQLStore) Update(ctx context.Context, batch *StoredBatch) error
- type Result
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Create(ctx context.Context, batch *StoredBatch) error
- func (s *SQLiteStore) Get(ctx context.Context, id string) (*StoredBatch, error)
- func (s *SQLiteStore) List(ctx context.Context, limit int, after string) ([]*StoredBatch, error)
- func (s *SQLiteStore) Update(ctx context.Context, batch *StoredBatch) error
- type Store
- type StoredBatch
Constants ¶
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 ¶
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 ¶
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 ¶
Result holds the initialized batch store and optional owned storage.
func NewWithSharedStorage ¶
NewWithSharedStorage creates a batch store using a shared storage connection.
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.