Skip to content

Commit 60c1964

Browse files
committed
Release v1.0.0 with tests, health endpoint, and proper error handling
1 parent 85203e9 commit 60c1964

5 files changed

Lines changed: 437 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "unique-id-generator"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
authors = ["Edwin Sundberg <edwin@edthing.com>"]
55
edition = "2021"
66

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ RUN cargo build --release
1010

1111
FROM debian:bookworm-slim
1212

13+
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
14+
1315
COPY --from=builder /project/target/release/unique-id-generator /project/unique-id-generator
1416

1517
EXPOSE 8080
1618

19+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
20+
CMD curl -f http://localhost:8080/health || exit 1
21+
1722
CMD ["/project/unique-id-generator"]

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ A Rust web service implementing Twitter's Snowflake ID generation algorithm. Gen
66

77
- Single ID generation endpoint
88
- Bulk ID generation (up to 4,096,000 IDs per request)
9-
- Handles clock drift and leap seconds
9+
- Health check endpoint for container orchestration
10+
- Handles clock drift and leap seconds with timeout protection
1011
- Thread-safe sequence management
12+
- Configurable worker threads
13+
- Comprehensive input validation
1114

1215
## API Endpoints
1316

@@ -21,17 +24,34 @@ Returns a single unique ID.
2124

2225
### GET /ids/{count}
2326

24-
Returns multiple unique IDs.
27+
Returns multiple unique IDs (count must be 1 to 4,096,000).
2528

2629
```json
2730
{"ids": ["123456789012345678", "123456789012345679", ...]}
2831
```
2932

33+
### GET /health
34+
35+
Health check endpoint for container orchestration (Kubernetes, Docker, etc.).
36+
37+
```json
38+
{"status": "healthy", "worker_id": 1}
39+
```
40+
41+
### Error Responses
42+
43+
All errors return JSON with a consistent format:
44+
45+
```json
46+
{"error": "Error message description"}
47+
```
48+
3049
## Configuration
3150

32-
| Environment Variable | Description | Required |
33-
|---------------------|-------------|----------|
34-
| `WORKER_ID` | Unique worker identifier (0-1023) | Yes |
51+
| Environment Variable | Description | Required | Default |
52+
|---------------------|-------------|----------|---------|
53+
| `WORKER_ID` | Unique worker identifier (0-1023) | Yes | - |
54+
| `WORKERS` | Number of HTTP worker threads | No | 1 |
3555

3656
## Running
3757

0 commit comments

Comments
 (0)