Files
worker/doc.go
T
Rene Nochebuena 2163b809b1 docs(worker): fix fictional launcher.Register/health.Register in doc examples (#2)
The package-doc examples showed a fictional launcher.Register / health.Register
API (and launcher.Append as a package func). Corrected to the real wiring:
lc.Append + web/health.NewHandler(...).ServeHTTP.
worker exposes lc.Append only — it is not observability.Checkable, so no health hook.

Documentation-only. No code, API, or dependency changes; version stays v1.1.0
(the v1.1.0 tag is moved to include this fix). Verified by compiling the
corrected pattern against the real API.

Reviewed-on: #2
Co-authored-by: Rene Nochebuena Guerrero <rene@nochebuena.dev>
Co-committed-by: Rene Nochebuena Guerrero <rene@nochebuena.dev>
2026-08-07 22:18:30 -06:00

42 lines
1.5 KiB
Go

// Package worker provides a concurrent goroutine pool with lifecycle management.
//
// # Lifecycle
//
// The component follows the lifecycle.Component contract:
// - OnInit: logs pool configuration; no goroutines are started.
// - OnStart: launches PoolSize goroutines that consume from the task queue.
// - OnStop: closes the task queue, cancels the pool context, then waits up to
// ShutdownTimeout for all goroutines to finish. Returns nil regardless of
// whether the drain completed before the deadline.
//
// Append to a launcher before starting:
//
// pool := worker.New(logger, cfg)
// lc.Append(pool)
//
// # Dispatching Tasks
//
// Dispatch is non-blocking. It returns false immediately when the buffer is full.
// A false return means the task was dropped — the caller is responsible for
// retry or overflow handling.
//
// ok := pool.Dispatch(func(ctx context.Context) error {
// return sendEmail(ctx, msg)
// })
// if !ok {
// // queue was full; handle backpressure
// }
//
// # Interface Segregation
//
// Inject Provider into callers that only dispatch work.
// Pass Component to the launcher registration site.
//
// # Configuration
//
// EINHERJAR_WORKER_POOL_SIZE — number of concurrent goroutines; default 5
// EINHERJAR_WORKER_BUFFER_SIZE — task queue capacity; default 100
// EINHERJAR_WORKER_TASK_TIMEOUT — per-task deadline (0 = no deadline); default 0s
// EINHERJAR_WORKER_SHUTDOWN_TIMEOUT — OnStop drain deadline; default 30s
package worker