Skip to content

Commit bf19573

Browse files
committed
docs: document contributor workflows and queue library architecture
- Add a CLAUDE.md file with development, testing, and build instructions for contributors using Claude Code - Document the core architecture, main abstractions, and key design patterns of the queue library - List supported worker implementations and entry points for queue usage - Include notes on code quality tools, security scanning, and testing practices Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 14d8b99 commit bf19573

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

CLAUDE.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Development Commands
6+
7+
### Testing
8+
9+
- `go test -v` - Run all tests with verbose output
10+
- `go test -race -v -covermode=atomic -coverprofile=coverage.out` - Run tests with race detection and coverage
11+
- `go test -v -run=^$ -count 5 -benchmem -bench . ./...` - Run benchmarks with memory stats
12+
13+
### Building
14+
15+
- `go build` - Build the package
16+
- `go mod download` - Download dependencies
17+
- `go mod tidy` - Clean up go.mod and go.sum
18+
19+
### Code Quality
20+
21+
- Uses golangci-lint for linting (configured in CI)
22+
- Bearer security scanning is enabled (config in bearer.yml)
23+
24+
## Architecture Overview
25+
26+
### Core Components
27+
28+
The queue library is built around these key abstractions:
29+
30+
1. **Queue** (`queue.go:28-42`) - Main queue implementation managing workers, job scheduling, retries, and graceful shutdown
31+
2. **Worker Interface** (`core/worker.go:9-25`) - Abstraction for task processors with Run, Shutdown, Queue, and Request methods
32+
3. **Ring Buffer** (`ring.go:14-26`) - Default in-memory worker implementation using circular buffer
33+
4. **Job Messages** (`job/job.go:14-50`) - Task wrapper with retry logic, timeouts, and payload handling
34+
35+
### Key Design Patterns
36+
37+
- **Worker Pool**: Queue manages multiple goroutines processing tasks concurrently
38+
- **Pluggable Workers**: Core Worker interface allows different backends (NSQ, NATS, Redis, etc.)
39+
- **Graceful Shutdown**: Atomic flags and sync.Once ensure clean shutdown
40+
- **Retry Logic**: Built-in exponential backoff with jitter for failed tasks
41+
- **Metrics**: Built-in tracking of submitted, completed, success, and failure counts
42+
43+
### Main Entry Points
44+
45+
- `NewPool(size, opts...)` - Creates queue with Ring buffer worker, auto-starts
46+
- `NewQueue(opts...)` - Creates queue with custom worker, requires manual Start()
47+
- `Queue(message)` - Enqueue a QueuedMessage
48+
- `QueueTask(func)` - Enqueue a function directly
49+
50+
### Worker Implementations
51+
52+
The library supports multiple queue backends through the Worker interface:
53+
54+
- **Ring** (default) - In-memory circular buffer
55+
- **NSQ** - Distributed messaging (external package)
56+
- **NATS** - Cloud-native messaging (external package)
57+
- **Redis** - Pub/Sub or Streams (external package)
58+
- **RabbitMQ** - Message broker (external package)
59+
60+
## Testing Notes
61+
62+
- Uses testify for assertions (`github.com/stretchr/testify`)
63+
- Includes benchmark tests in `benchmark_test.go` and `job/benchmark_test.go`
64+
- Uses go.uber.org/goleak to detect goroutine leaks
65+
- Mock interfaces generated with go.uber.org/mock in `mocks/` directory

0 commit comments

Comments
 (0)