This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
go test -v- Run all tests with verbose outputgo test -race -v -covermode=atomic -coverprofile=coverage.out- Run tests with race detection and coveragego test -v -run=^$ -count 5 -benchmem -bench . ./...- Run benchmarks with memory stats
go build- Build the packagego mod download- Download dependenciesgo mod tidy- Clean up go.mod and go.sum
- Uses golangci-lint for linting (configured in CI)
The queue library is built around these key abstractions:
- Queue (
queue.go:28-42) - Main queue implementation managing workers, job scheduling, retries, and graceful shutdown - Worker Interface (
core/worker.go:9-25) - Abstraction for task processors with Run, Shutdown, Queue, and Request methods - Ring Buffer (
ring.go:14-26) - Default in-memory worker implementation using circular buffer - Job Messages (
job/job.go:14-50) - Task wrapper with retry logic, timeouts, and payload handling
- Worker Pool: Queue manages multiple goroutines processing tasks concurrently
- Pluggable Workers: Core Worker interface allows different backends (NSQ, NATS, Redis, etc.)
- Graceful Shutdown: Atomic flags and sync.Once ensure clean shutdown
- Retry Logic: Built-in exponential backoff with jitter for failed tasks
- Metrics: Built-in tracking of submitted, completed, success, and failure counts
NewPool(size, opts...)- Creates queue with Ring buffer worker, auto-startsNewQueue(opts...)- Creates queue with custom worker, requires manual Start()Queue(message)- Enqueue a QueuedMessageQueueTask(func)- Enqueue a function directly
The library supports multiple queue backends through the Worker interface:
- Ring (default) - In-memory circular buffer
- NSQ - Distributed messaging (external package)
- NATS - Cloud-native messaging (external package)
- Redis - Pub/Sub or Streams (external package)
- RabbitMQ - Message broker (external package)
- Uses testify for assertions (
github.com/stretchr/testify) - Includes benchmark tests in
benchmark_test.goandjob/benchmark_test.go - Uses go.uber.org/goleak to detect goroutine leaks
- Mock interfaces generated with go.uber.org/mock in
mocks/directory