Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Docs: `docs/integration-testing.md` now describes the real CI workflow and queue module paths.

## [2.2.0] - 2026-10-11

A fix and cleanup release. It is a minor version because it adds public API with default
Expand Down
37 changes: 24 additions & 13 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,21 @@ The codebase follows a modular architecture with clear separation of concerns:
- Job priorities: Background, Low, Normal, High, Critical
- Supports delayed execution, configurable retry attempts, and priority levels

2. **Queue (`src/queue.rs`)**
- `DatabaseQueue` trait defines the interface for database operations
- `JobQueue<DB>` generic struct wraps database connection pools
- Database-specific implementations in `postgres` and `mysql` modules
- Uses database transactions for atomic job operations
- Priority-aware job selection with weighted algorithms

3. **Worker (`src/worker.rs`)**
- `Worker<DB>` processes jobs from specific queues
- Configurable polling intervals, retry delays, max retries, and priority weights
- Support for strict priority or weighted priority scheduling
- `WorkerPool<DB>` manages multiple workers with graceful shutdown
- Uses async channels for shutdown coordination
2. **Queue (`src/queue/`)**
- `mod.rs`: the `DatabaseQueue` trait (the interface for database operations) and the generic `JobQueue<DB>` wrapping a connection pool
- `postgres.rs` / `mysql.rs`: the dialect-specific implementations (SQL, row types, locking)
- `backend.rs`: helpers shared by both backends (transactions and conflict retries, column encoding, cron and dequeue helpers)
- `row.rs`: dialect-independent row decoding (column lists, status, result config and encryption columns)
- `lifecycle.rs`: the job lifecycle state machine (manual transitions and worker run outcomes)
- `payload_encryption.rs`, `memory_results.rs`: payload sealing and in-memory result storage
- `test.rs`: the in-memory `TestQueue` (feature `test`)
- Priority-aware job selection with weighted algorithms; atomic transitions in transactions

3. **Worker (`src/worker.rs` and `src/worker/`)**
- `worker.rs`: `Worker<DB>` processes jobs from specific queues (polling intervals, retry delays, priority weights, strict or weighted scheduling)
- `worker/pool.rs`: `WorkerPool<DB>` manages multiple workers with graceful shutdown, supervision and periodic maintenance
- `worker/autoscale.rs`: autoscaling configuration and decisions
- `worker/hooks.rs`: job lifecycle event hooks

4. **Priority System (`src/priority.rs`)**
- `JobPriority` enum with 5 levels: Background, Low, Normal, High, Critical
Expand All @@ -105,6 +107,15 @@ The codebase follows a modular architecture with clear separation of concerns:
- `HammerworkError` enum using thiserror for structured error handling
- Wraps SQLx, serialization, and custom errors

6. **Other modules**: `migrations/` (versioned SQL migrations per backend), `cron`, `retry`, `batch`, `workflow`, `spawn`, `archive`, `rate_limit`, `stats`, `metrics`, `events`, `streaming`, `webhooks`, `alerting`, `tracing`, `encryption/`, `config`, `task_tracker`. Most are feature-gated; see `[features]` in `Cargo.toml`.

### Workspace Crates

- `hammerwork` (repo root): the library
- `cargo-hammerwork/`: the CLI (`cargo hammerwork ...`)
- `hammerwork-web/`: the web dashboard and REST API
- `integrations/`: Docker-based integration test binaries

### Database Schema

Both PostgreSQL and MySQL implementations use a single table `hammerwork_jobs` with:
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ exclude = [
"docker-compose.yml",
"config/",
"scripts/",
"test-mysql-cli.sh",
]
version.workspace = true
edition.workspace = true
Expand Down
58 changes: 0 additions & 58 deletions MERMAID_EXAMPLE.md

This file was deleted.

35 changes: 16 additions & 19 deletions docs/integration-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ hammerwork/
│ ├── postgres-integration/ # PostgreSQL-specific tests
│ └── mysql-integration/ # MySQL-specific tests
└── .github/workflows/
└── integration.yml # CI/CD pipeline
└── ci.yml # CI/CD pipeline
```

### Test Categories
Expand Down Expand Up @@ -219,30 +219,27 @@ Tests measure and validate:

### GitHub Actions Workflow

The CI pipeline (`.github/workflows/integration.yml`) runs:
The CI pipeline (`.github/workflows/ci.yml`) runs:

1. **Unit Tests**: Fast validation without dependencies
2. **PostgreSQL Integration**: Full database testing
3. **MySQL Integration**: MySQL-specific validation
4. **Docker Tests**: Containerized scenario testing
5. **Security Audit**: Vulnerability scanning
6. **Performance Tests**: Benchmark execution (scheduled)
1. **rustfmt**, **clippy** (all features) and an **MSRV** build
2. **Feature combinations**: the library with each backend alone, no features, and the optional subsystems
3. **Unit and doc tests** (`test`)
4. **PostgreSQL** and **MySQL integration** suites against service containers
5. **Coverage** with a line-coverage floor
6. **Security audit**: vulnerability scanning

### Triggers

- **Push/PR**: On master/main/develop branches
- **Scheduled**: Daily performance benchmarks
- **Manual**: `[benchmark]` in commit message
- **Push** to `master`, **pull requests** against `master`, and manual runs (`workflow_dispatch`)

### Test Matrix

| Job | Database | Purpose |
|-----|----------|---------|
| unit-tests | None | Fast validation |
| postgres-integration | PostgreSQL 16 | Feature testing |
| mysql-integration | MySQL 8.0 | Feature testing |
| docker-tests | Both | Container validation |
| performance-tests | Both | Benchmark regression |
| test | None | Unit and doc tests |
| postgres | PostgreSQL | Integration suite |
| mysql | MySQL | Integration suite |
| coverage | Both | Line-coverage floor |

## Docker Testing

Expand Down Expand Up @@ -349,7 +346,7 @@ docker system prune
- Add feature-specific tests to `mysql-integration/src/main.rs`

3. **Update CI Pipeline**:
- Add new test validation to `.github/workflows/integration.yml`
- Add new test validation to `.github/workflows/ci.yml`

### Database Schema Changes

Expand All @@ -358,8 +355,8 @@ docker system prune
- Modify `config/init-mysql.sql`

2. **Update Database Queue Implementations**:
- Modify PostgreSQL implementation in `src/queue.rs`
- Modify MySQL implementation in `src/queue.rs`
- Modify PostgreSQL implementation in `src/queue/postgres.rs`
- Modify MySQL implementation in `src/queue/mysql.rs`

3. **Add Migration Tests**:
- Test schema compatibility
Expand Down
22 changes: 6 additions & 16 deletions hammerwork-web/src/api/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
use super::history::JobHistory;
use super::{
ApiResponse, FilterParams, PaginatedResponse, PaginationMeta, PaginationParams, error_reply,
internal_error, json_reply,
internal_error, json_reply, with_shared,
};
use hammerwork::{
JobId, JobStatus,
Expand Down Expand Up @@ -259,32 +259,32 @@ where
let archive_jobs = warp::path!("archive" / "jobs")
.and(warp::post())
.and(crate::security::json_body())
.and(with_queue(queue.clone()))
.and(with_shared(queue.clone()))
.and_then(handle_archive_jobs);

let list_archived = warp::path!("archive" / "jobs")
.and(warp::get())
.and(super::with_pagination())
.and(with_archive_filters())
.and(with_queue(queue.clone()))
.and(with_shared(queue.clone()))
.and_then(handle_list_archived_jobs);

let restore_job = warp::path!("archive" / "jobs" / String / "restore")
.and(warp::post())
.and(crate::security::json_body())
.and(with_queue(queue.clone()))
.and(with_shared(queue.clone()))
.and_then(handle_restore_job);

let purge_jobs = warp::path!("archive" / "purge")
.and(warp::delete())
.and(crate::security::json_body())
.and(with_queue(queue.clone()))
.and(with_shared(queue.clone()))
.and_then(handle_purge_jobs);

let archive_stats = warp::path!("archive" / "stats")
.and(warp::get())
.and(warp::query::<FilterParams>())
.and(with_queue(queue.clone()))
.and(with_shared(queue.clone()))
.and_then(handle_archive_stats);

archive_jobs
Expand All @@ -294,16 +294,6 @@ where
.or(archive_stats)
}

/// Helper to inject queue into handlers
fn with_queue<Q>(
queue: Arc<Q>,
) -> impl Filter<Extract = (Arc<Q>,), Error = std::convert::Infallible> + Clone
where
Q: JobHistory + 'static,
{
warp::any().map(move || queue.clone())
}

/// Extract archive filter parameters from query string
fn with_archive_filters()
-> impl Filter<Extract = (ArchiveFilterParams,), Error = warp::Rejection> + Clone {
Expand Down
4 changes: 2 additions & 2 deletions hammerwork-web/src/api/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use super::{
ApiResponse, FilterParams, PaginatedResponse, PaginationMeta, PaginationParams, SortParams,
with_filters, with_pagination, with_sort,
};
use super::{error_reply, json_reply};
use super::{error_reply, json_reply, with_shared};
use hammerwork::queue::DatabaseQueue;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
Expand Down Expand Up @@ -161,7 +161,7 @@ pub fn routes<T>(
where
T: DatabaseQueue + Send + Sync + 'static,
{
let queue_filter = warp::any().map(move || queue.clone());
let queue_filter = with_shared(queue);

let list_jobs = warp::path("jobs")
.and(warp::path::end())
Expand Down
11 changes: 11 additions & 0 deletions hammerwork-web/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ pub async fn handle_api_error(
))
}

/// Hand a clone of shared state (a queue handle, system state, ...) to a handler.
pub fn with_shared<T>(
value: T,
) -> impl warp::Filter<Extract = (T,), Error = std::convert::Infallible> + Clone
where
T: Clone + Send,
{
use warp::Filter;
warp::any().map(move || value.clone())
}

/// Extract pagination parameters from query string
pub fn with_pagination()
-> impl warp::Filter<Extract = (PaginationParams,), Error = warp::Rejection> + Clone {
Expand Down
4 changes: 2 additions & 2 deletions hammerwork-web/src/api/queues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ use super::{
ApiResponse, FilterParams, PaginatedResponse, PaginationMeta, PaginationParams, SortParams,
with_filters, with_pagination, with_sort,
};
use super::{error_reply, json_reply};
use super::{error_reply, json_reply, with_shared};
use hammerwork::queue::DatabaseQueue;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn routes<T>(
where
T: JobHistory + 'static,
{
let queue_filter = warp::any().map(move || queue.clone());
let queue_filter = with_shared(queue);

let list_queues = warp::path("queues")
.and(warp::path::end())
Expand Down
6 changes: 3 additions & 3 deletions hammerwork-web/src/api/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
//! ```

use super::history::{ErrorGroup, JobHistory, MAX_BUCKETS, hour_floor};
use super::{ApiResponse, error_reply, json_reply};
use super::{ApiResponse, error_reply, json_reply, with_shared};
use hammerwork::queue::DatabaseQueue;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand Down Expand Up @@ -249,8 +249,8 @@ pub fn routes<T>(
where
T: JobHistory + 'static,
{
let queue_filter = warp::any().map(move || queue.clone());
let state_filter = warp::any().map(move || system_state.clone());
let queue_filter = with_shared(queue);
let state_filter = with_shared(system_state);

let overview = warp::path("stats")
.and(warp::path("overview"))
Expand Down
6 changes: 3 additions & 3 deletions hammerwork-web/src/api/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
//! ```

use super::history::{FinishedKind, JobHistory, TableMaintenance, maintenance_tables};
use super::{ApiResponse, error_reply, json_reply};
use super::{ApiResponse, error_reply, json_reply, with_shared};
use hammerwork::queue::DatabaseQueue;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
Expand Down Expand Up @@ -254,8 +254,8 @@ pub fn routes<T>(
where
T: JobHistory + 'static,
{
let queue_filter = warp::any().map(move || queue.clone());
let state_filter = warp::any().map(move || system_state.clone());
let queue_filter = with_shared(queue);
let state_filter = with_shared(system_state);

let info = warp::path("system")
.and(warp::path("info"))
Expand Down
Loading
Loading