feat(worker)!: promote to v1.0.0 — add Len() to Provider, bump deps to v1

Add Len() int to Provider interface; returns current queue depth for
observability and test assertions. Bump launcher and logz to v1.0.1.
Go directive bumped to 1.26. API committed as stable.
This commit is contained in:
2026-05-12 17:51:34 +00:00
parent 631c98396e
commit f07782d583
6 changed files with 47 additions and 7 deletions

1
.gitea/CODEOWNERS Normal file
View File

@@ -0,0 +1 @@
* @go/CoreDevelopers @go/Agents

View File

@@ -5,6 +5,25 @@ All notable changes to this module will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.0] - 2026-05-12
### Added
- `Len() int` on `Provider` — returns the current number of tasks waiting in the queue.
Useful for observability, logging backpressure state, and tests.
### Changed
- Go directive bumped from 1.25 to 1.26
- `launcher` and `logz` dependencies bumped to v1.0.1
### Stabilization
- API committed as stable. `Task`, `Provider`, `Component`, `Config`, and `New` are
unchanged from v0.9.0 except for the addition of `Len`.
[1.0.0]: https://code.nochebuena.dev/go/worker/compare/v0.9.0...v1.0.0
## [0.9.0] - 2026-03-18
### Added

6
go.mod
View File

@@ -1,8 +1,8 @@
module code.nochebuena.dev/go/worker
go 1.25
go 1.26
require (
code.nochebuena.dev/go/launcher v0.9.0
code.nochebuena.dev/go/logz v0.9.0
code.nochebuena.dev/go/launcher v1.0.1
code.nochebuena.dev/go/logz v1.0.1
)

8
go.sum
View File

@@ -1,4 +1,4 @@
code.nochebuena.dev/go/launcher v0.9.0 h1:dJHonA9Xm03AQKK0919FJaQn9ZKHZ+RZfB9yxjnx3TA=
code.nochebuena.dev/go/launcher v0.9.0/go.mod h1:IBtntmbnyddukjEhxlc7Ysdzz9nZsnd9+8FzAIHt77g=
code.nochebuena.dev/go/logz v0.9.0 h1:wfV7vtI4V/8ED7Hm31Fbql7Y5iOGrlHN4X8Z5ajTZZE=
code.nochebuena.dev/go/logz v0.9.0/go.mod h1:qODhSbKb+tWE7rdhHLcKweiP5CgwIaWoZxadCT3bQV8=
code.nochebuena.dev/go/launcher v1.0.1 h1:hbPV8jNtyxfchrT7igzz3M2tKGI3bm8uWkHBXRvSPgg=
code.nochebuena.dev/go/launcher v1.0.1/go.mod h1:1KwndVuqm31JN9Dpl9YvOmlogPlKKzoDMo9aRFkYwmM=
code.nochebuena.dev/go/logz v1.0.1 h1:kK9aZo19L208CwCr2D/dbSOMaOv62cXsigMSsdFu+8Y=
code.nochebuena.dev/go/logz v1.0.1/go.mod h1:YNpNm03fURm2v0ySh/477z9AJhtfRcd9rFOW6fFqgNM=

View File

@@ -16,6 +16,8 @@ type Task func(ctx context.Context) error
type Provider interface {
// Dispatch queues a task. Returns false if the queue is full (backpressure).
Dispatch(task Task) bool
// Len returns the current number of tasks waiting in the queue.
Len() int
}
// Component adds lifecycle management to Provider.
@@ -103,6 +105,8 @@ func (w *workerComponent) OnStop() error {
return nil
}
func (w *workerComponent) Len() int { return len(w.taskQueue) }
func (w *workerComponent) Dispatch(task Task) bool {
select {
case w.taskQueue <- task:

View File

@@ -180,6 +180,22 @@ func TestWorker_TaskError(t *testing.T) {
c.OnStop() // should not panic
}
func TestWorker_Len(t *testing.T) {
c := New(newLogger(), Config{PoolSize: 1, BufferSize: 10, ShutdownTimeout: time.Second})
if err := c.OnInit(); err != nil {
t.Fatalf("OnInit: %v", err)
}
// Before start, workers are not running — queued tasks stay in the channel.
blocked := make(chan struct{})
c.Dispatch(func(ctx context.Context) error { <-blocked; return nil })
c.Dispatch(func(ctx context.Context) error { <-blocked; return nil })
if got := c.Len(); got != 2 {
t.Errorf("Len() = %d, want 2", got)
}
close(blocked)
_ = c.OnStop()
}
func TestWorker_Lifecycle(t *testing.T) {
c := New(newLogger(), Config{PoolSize: 2, BufferSize: 10, ShutdownTimeout: time.Second})
if err := c.OnInit(); err != nil {