Skip to content
Storage & Embedded UI

Storage & Embedded UI

Embedded UI

ui.Handler(storage core.Storage, opts ...Option) http.Handler

Creates an HTTP handler serving the dashboard and Connect-RPC API.

import "github.com/jdziat/simple-durable-jobs/v4/ui"

mux.Handle("/jobs/", http.StripPrefix("/jobs", ui.Handler(storage,
    ui.WithQueue(queue),
    ui.WithContext(ctx),
    ui.WithStatsRetention(7 * 24 * time.Hour),
    ui.WithMiddleware(authMiddleware),
)))

UI Options

OptionDescription
WithQueue(q)Provides queue for event streaming and scheduled jobs view
WithContext(ctx)Lifecycle context for background goroutines; when cancelled, workers flush and exit
WithStatsRetention(d)How long stats rows are kept (default: 31 days, covering the dashboard’s longest 30d window)
WithMiddleware(mw)Wraps handler with middleware (auth, logging, etc.)

Storage

NewGormStorage(db *gorm.DB) *GormStorage

Creates a new GORM-based storage implementation.

Applies a bounded default connection pool unless the pool is already sized. For PostgreSQL/MySQL it installs DefaultPoolConfig() (MaxOpen 25, MaxIdle 10, MaxLifetime 5min, MaxIdleTime 1min); for SQLite it installs a small SQLite-safe pool (MaxOpen 4, MaxIdle 2, no connection expiry). The default is skipped when the caller has already bounded the pool (a non-zero MaxOpenConns set before construction) or uses NewGormStorageWithPool, so unbounded is no longer the out-of-the-box default and presets are an optional optimization rather than a requirement.

NewGormStorageWithPool(db *gorm.DB, opts ...PoolOption) (*GormStorage, error)

Creates storage with connection pool configuration.

Pool Presets

jobs.DefaultPoolConfig()              // Sensible defaults
jobs.HighConcurrencyPoolConfig()      // High-concurrency workloads
jobs.LowLatencyPoolConfig()          // Low-latency optimized
jobs.ResourceConstrainedPoolConfig() // Limited resources
PresetMaxOpenMaxIdleMaxLifetimeMaxIdleTime
DefaultPoolConfig()25105min1min
HighConcurrencyPoolConfig()1002510min2min
LowLatencyPoolConfig()504015min5min
ResourceConstrainedPoolConfig()1053min30s

Pool Option Functions

MaxOpenConns(n int) PoolOption

Sets the maximum number of open connections.

MaxIdleConns(n int) PoolOption

Sets the maximum number of idle connections.

ConnMaxLifetime(d time.Duration) PoolOption

Sets the maximum connection lifetime.

ConnMaxIdleTime(d time.Duration) PoolOption

Sets the maximum idle time for connections.

ConfigurePool(db *gorm.DB, opts ...PoolOption) error

Applies pool configuration to a GORM database connection.