Documentation
¶
Overview ¶
Package azync provides durable background jobs and a CQRS event bus for Go, unified over a single job table with pluggable storage drivers.
A Core is the shared root: it owns the storage driver, the resolved layered defaults and the logger. Open builds one from a DSN, resolving the driver from its scheme through a registry populated by a blank import (in the style of database/sql, see RegisterDriver); New wraps an already-constructed driver.Store directly. Neither migrates automatically — call Core.Migrate once the driver supports it.
The queue and event runtimes each compose over a Core: their New shares one (so jobs and event deliveries live behind a single connection pool, schema and migrations table), or their own Open builds a private one. Every runtime setting resolves in layers — a runtime-specific option overrides a Core option, which overrides the built-in Defaults — so a queue- or event-only override never has to touch the shared Core.
Index ¶
- func RegisterDriver(scheme string, opener driver.Opener)
- type Core
- type Defaults
- type Option
- func PollOnly() Option
- func WithCompletedRetention(d time.Duration) Option
- func WithDeadRetention(d time.Duration) Option
- func WithDefaultConcurrency(n int) Option
- func WithDefaultMaxAttempts(n int) Option
- func WithFetchBatchSize(n int) Option
- func WithFetchCooldown(d time.Duration) Option
- func WithFetchPollInterval(d time.Duration) Option
- func WithIdleBackoffMax(d time.Duration) Option
- func WithLeaseTTL(d time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxConcurrency(n int) Option
- func WithMaxReaps(n int) Option
- func WithMigrationsTable(table string) Option
- func WithNotifyChannel(channel string) Option
- func WithSchema(schema string) Option
- func WithShutdownDrain(d time.Duration) Option
- func WithStatsRetention(d time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterDriver ¶
RegisterDriver registers a driver.Opener under a DSN scheme, in the style of database/sql. Drivers call it from an init function so a blank import wires them in. It panics if scheme is empty, opener is nil, or the scheme is already registered.
Types ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core is the shared root: it owns the storage driver, the resolved defaults and the logger. The queue and event runtimes compose over one Core, either sharing it (queue.New(core)) or owning a private one (queue.Open(dsn)).
func New ¶
New builds a Core over an already-constructed Store. Infrastructure options (WithSchema, WithNotifyChannel, WithMigrationsTable, PollOnly) are rejected here because the store is already built; only the logger and defaults options apply.
func Open ¶
Open resolves the driver for the DSN's scheme from the registry, builds the driver.Config from the options, and opens a Store. The DSN scheme selects the driver; register one with a blank import. Open never migrates and never includes the DSN (which may carry credentials) in an error.
func (*Core) Defaults ¶
Defaults returns the resolved shared defaults. Runtimes read these as their baseline and may override individual values per runtime.
type Defaults ¶
type Defaults struct {
// LeaseTTL is how long a worker holds a job before its lease is reclaimable.
LeaseTTL time.Duration
// DefaultMaxAttempts is the retry budget applied to jobs enqueued without an
// explicit budget.
DefaultMaxAttempts int
// ShutdownDrain is how long Close waits for in-flight jobs to settle.
ShutdownDrain time.Duration
// MaxConcurrency caps the total concurrent handlers across a runtime.
MaxConcurrency int
// DefaultConcurrency is the per-kind handler concurrency when unset.
DefaultConcurrency int
// FetchBatchSize is how many jobs one dequeue leases at a time.
FetchBatchSize int
// FetchPollInterval is the polling period when no wakeups arrive.
FetchPollInterval time.Duration
// FetchCooldown is the pause after a full batch before fetching again.
FetchCooldown time.Duration
// IdleBackoffMax caps the backoff a fetch loop reaches while idle.
IdleBackoffMax time.Duration
// MaxReaps is how many lease expirations a job survives before it is killed.
MaxReaps int
// StatsRetention is how long daily stat counters are kept; 0 keeps them
// forever.
StatsRetention time.Duration
// CompletedRetention is how long succeeded jobs are kept; 0 keeps them
// forever.
CompletedRetention time.Duration
// DeadRetention is how long dead (exhausted-retry) jobs are kept; 0 keeps
// them forever. Unlike CompletedRetention, dead jobs are diagnostic
// history an operator may want to inspect indefinitely, so the default is
// conservative: opt in explicitly to automatic removal.
DeadRetention time.Duration
}
Defaults are the shared baseline settings a Core resolves from options. Each value is a starting point the queue and event runtimes may override per runtime (package option > core option > default).
type Option ¶
type Option func(*coreConfig) error
Option configures a Core. Options compose; later options win.
func PollOnly ¶
func PollOnly() Option
PollOnly disables push wakeups, forcing the always-correct polling path. Infrastructure option: valid only with Open.
func WithCompletedRetention ¶
WithCompletedRetention sets Defaults.CompletedRetention. A negative value is rejected; zero means retain succeeded jobs forever.
func WithDeadRetention ¶ added in v0.0.4
WithDeadRetention sets Defaults.DeadRetention. A negative value is rejected; zero (the default) means retain dead jobs forever.
func WithDefaultConcurrency ¶
WithDefaultConcurrency sets Defaults.DefaultConcurrency. Must be positive.
func WithDefaultMaxAttempts ¶
WithDefaultMaxAttempts sets Defaults.DefaultMaxAttempts. Must be positive.
func WithFetchBatchSize ¶
WithFetchBatchSize sets Defaults.FetchBatchSize. Must be positive.
func WithFetchCooldown ¶
WithFetchCooldown sets Defaults.FetchCooldown. Must be positive.
func WithFetchPollInterval ¶
WithFetchPollInterval sets Defaults.FetchPollInterval. Must be positive.
func WithIdleBackoffMax ¶
WithIdleBackoffMax sets Defaults.IdleBackoffMax. Must be positive.
func WithLeaseTTL ¶
WithLeaseTTL sets Defaults.LeaseTTL. Must be positive.
func WithLogger ¶
WithLogger sets the Core's structured logger. A nil logger is rejected.
func WithMaxConcurrency ¶
WithMaxConcurrency sets Defaults.MaxConcurrency. Must be positive.
func WithMaxReaps ¶
WithMaxReaps sets Defaults.MaxReaps. Must be positive.
func WithMigrationsTable ¶
WithMigrationsTable overrides the migration version-tracking table name (default azync_migrations in the pg driver). Infrastructure option: valid only with Open.
func WithNotifyChannel ¶
WithNotifyChannel sets the driver's wakeup channel name. Infrastructure option: valid only with Open.
func WithSchema ¶
WithSchema isolates azync's tables in the named backend schema (empty uses the backend default). The name is validated as an identifier. Infrastructure option: valid only with Open.
func WithShutdownDrain ¶
WithShutdownDrain sets Defaults.ShutdownDrain. Must be positive.
func WithStatsRetention ¶
WithStatsRetention sets Defaults.StatsRetention. A negative value is rejected; zero means retain stat counters forever.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dag provides durable static DAGs over an azync Core: a task graph declared up front, executed by ordinary job machinery, with durable timers, signals, task results, compensation and a per-DAG failure policy.
|
Package dag provides durable static DAGs over an azync Core: a task graph declared up front, executed by ordinary job machinery, with durable timers, signals, task results, compensation and a per-DAG failure policy. |
|
Package driver defines the backend-agnostic contract that azync storage drivers implement.
|
Package driver defines the backend-agnostic contract that azync storage drivers implement. |
|
drivertest
Package drivertest provides a public conformance suite that any azync storage driver can run against its own driver.Store to prove it honors the backend-agnostic contract.
|
Package drivertest provides a public conformance suite that any azync storage driver can run against its own driver.Store to prove it honors the backend-agnostic contract. |
|
azyncpgx
module
|
|
|
Package event is a durable CQRS event bus over an azync Core.
|
Package event is a durable CQRS event bus over an azync Core. |
|
eventtest
Package eventtest provides an in-memory publisher seam for tests: a Recorder that satisfies the same Publish signature as the real event.Publisher, so application code under test can publish without a running runtime and the test can assert on what was published.
|
Package eventtest provides an in-memory publisher seam for tests: a Recorder that satisfies the same Publish signature as the real event.Publisher, so application code under test can publish without a running runtime and the test can assert on what was published. |
|
internal
|
|
|
clock
Package clock provides a minimal injectable time source so runtimes and the in-memory test store can be driven by a controllable clock in tests while using the real wall clock in production.
|
Package clock provides a minimal injectable time source so runtimes and the in-memory test store can be driven by a controllable clock in tests while using the real wall clock in production. |
|
drivertest
Package drivertest provides an in-memory driver.Store used by the queue and event runtimes' unit tests.
|
Package drivertest provides an in-memory driver.Store used by the queue and event runtimes' unit tests. |
|
engine
Package engine is the shared fetch/execute/settle/maintenance machinery the queue and event runtimes are built on, neutral over driver.Source.
|
Package engine is the shared fetch/execute/settle/maintenance machinery the queue and event runtimes are built on, neutral over driver.Source. |
|
Package queue provides durable background jobs over an azync Core.
|
Package queue provides durable background jobs over an azync Core. |
|
Package watch streams row-change hints from the backend so external observers — ops UIs, SSE/WebSocket bridges, cache invalidators — can react to state transitions without polling.
|
Package watch streams row-change hints from the backend so external observers — ops UIs, SSE/WebSocket bridges, cache invalidators — can react to state transitions without polling. |
|
Package workflow is the workflow-as-code (WAC) runtime: workflows and Operations defined as ordinary Go functions, executed by deterministic replay over an append-only history.
|
Package workflow is the workflow-as-code (WAC) runtime: workflows and Operations defined as ordinary Go functions, executed by deterministic replay over an append-only history. |
|
kernel
Package kernel is the pure in-memory history/command/replay engine for workflow-as-code.
|
Package kernel is the pure in-memory history/command/replay engine for workflow-as-code. |