Skip to content

Commit c1d9dba

Browse files
CodingAnarchyclaude
andcommitted
feat: Add comprehensive job archiving system and bump to v1.3.0
Add complete job archiving functionality with policy-driven retention, compression, and web dashboard integration. ## Core Archive Features - Policy-based job archival with configurable retention periods - Payload compression using gzip with configurable levels - Archive table schema with PostgreSQL and MySQL support - Restore archived jobs back to pending status - Purge old archived jobs for compliance requirements ## CLI Integration - Archive command for policy-driven job archival - Restore command for individual job restoration - List-archived command with filtering and pagination - Purge-archived command for compliance cleanup - Archive statistics and monitoring ## Web Dashboard Integration - Complete archive management UI with statistics cards - Archive jobs table with filtering and pagination - Archive modal for policy configuration and execution - Archive statistics modal with detailed metrics - Job restoration workflow with audit trails - Real-time archive statistics and compression tracking ## Technical Implementation - Extended DatabaseQueue trait with archive methods - Database migrations (010) for archive table setup - Comprehensive doctests and test coverage - Archive API endpoints with REST interface - Enhanced error handling and user notifications ## Version Updates - Bump workspace version to 1.3.0 - Update README and CHANGELOG documentation - Migrate hammerwork-web to workspace dependencies - Add roadmap item for WebSocket archive events 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent eb4d256 commit c1d9dba

30 files changed

+5331
-93
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.3.0] - 2025-07-01
9+
10+
### Added
11+
- **🗄️ Job Archiving & Retention System**
12+
- Policy-driven job archival with configurable retention periods per job status
13+
- Payload compression using gzip for efficient long-term storage
14+
- Archive table (`hammerwork_jobs_archive`) with compressed payloads
15+
- Restore archived jobs back to pending status when needed
16+
- Purge old archived jobs for compliance requirements (GDPR, data retention)
17+
- Comprehensive archival statistics and monitoring
18+
- CLI commands for archive management in `cargo-hammerwork`
19+
20+
### Enhanced
21+
- **⚡ Archive Management Features**
22+
- Automatic archival based on job age and status (Completed, Failed, Dead, TimedOut)
23+
- Configurable compression levels (0-9) with integrity verification
24+
- Batch processing for efficient large-scale archival operations
25+
- Archive metadata tracking (reason, timestamp, who initiated)
26+
- List and search archived jobs with pagination support
27+
- Database schema migration (010) for archive table setup
28+
29+
### Technical Implementation
30+
- New `archive` module with `ArchivalPolicy`, `ArchivalConfig`, and `JobArchiver` types
31+
- Extended `DatabaseQueue` trait with archival methods for all database backends
32+
- PostgreSQL and MySQL implementations with optimized archive queries
33+
- Comprehensive doctests and unit tests for all archival functionality
34+
- Archive CLI commands: `archive`, `restore`, `list-archived`, `purge-archived`
35+
836
## [1.2.2] - 2025-07-01
937

1038
### Added

Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
resolver = "2"
1010

1111
[workspace.package]
12-
version = "1.2.2"
12+
version = "1.3.0"
1313
edition = "2024"
1414
license = "MIT"
1515
repository = "https://github.com/CodingAnarchy/hammerwork"
@@ -19,7 +19,7 @@ documentation = "https://docs.rs/hammerwork"
1919
rust-version = "1.86"
2020

2121
[workspace.dependencies]
22-
hammerwork = { version = "1.2.2", path = "." }
22+
hammerwork = { version = "1.3.0", path = "." }
2323
tokio = { version = "1.0", features = ["full"] }
2424
sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "chrono", "uuid", "json"] }
2525
chrono = { version = "0.4", features = ["serde"] }
@@ -44,6 +44,11 @@ indicatif = "0.17"
4444
toml = "0.8"
4545
dirs = "5.0"
4646
tempfile = "3.8"
47+
flate2 = "1.0"
48+
bcrypt = "0.15"
49+
base64 = "0.22"
50+
tokio-tungstenite = "0.21"
51+
futures-util = "0.3"
4752

4853
[package]
4954
name = "hammerwork"
@@ -82,6 +87,7 @@ opentelemetry = { version = "0.22", optional = true }
8287
opentelemetry_sdk = { version = "0.22", features = ["rt-tokio"], optional = true }
8388
opentelemetry-otlp = { version = "0.15", features = ["tokio"], optional = true }
8489
tracing-opentelemetry = { version = "0.23", optional = true }
90+
flate2 = { workspace = true }
8591

8692
[features]
8793
default = ["metrics", "alerting"]

README.md

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ A high-performance, database-driven job queue for Rust with comprehensive featur
88
- **🧪 TestQueue Framework**: Complete in-memory testing implementation with MockClock for deterministic testing of time-dependent features, workflows, and job processing
99
- **🔍 Job Tracing & Correlation**: Comprehensive distributed tracing with OpenTelemetry integration, trace IDs, correlation IDs, and lifecycle event hooks
1010
- **🔗 Job Dependencies & Workflows**: Create complex data processing pipelines with job dependencies, sequential chains, and parallel processing with synchronization barriers
11+
- **🗄️ Job Archiving & Retention**: Policy-driven archival with configurable retention periods, payload compression, and automated cleanup for compliance and performance
1112
- **Multi-database support**: PostgreSQL and MySQL backends with optimized dependency queries
1213
- **Advanced retry strategies**: Exponential backoff, linear, Fibonacci, and custom retry patterns with jitter
1314
- **Job prioritization**: Five priority levels with weighted and strict scheduling algorithms
@@ -29,15 +30,15 @@ A high-performance, database-driven job queue for Rust with comprehensive featur
2930
```toml
3031
[dependencies]
3132
# Default features include metrics and alerting
32-
hammerwork = { version = "1.2", features = ["postgres"] }
33+
hammerwork = { version = "1.3", features = ["postgres"] }
3334
# or
34-
hammerwork = { version = "1.2", features = ["mysql"] }
35+
hammerwork = { version = "1.3", features = ["mysql"] }
3536

3637
# With distributed tracing
37-
hammerwork = { version = "1.2", features = ["postgres", "tracing"] }
38+
hammerwork = { version = "1.3", features = ["postgres", "tracing"] }
3839

3940
# Minimal installation
40-
hammerwork = { version = "1.2", features = ["postgres"], default-features = false }
41+
hammerwork = { version = "1.3", features = ["postgres"], default-features = false }
4142
```
4243

4344
**Feature Flags**: `postgres`, `mysql`, `metrics` (default), `alerting` (default), `tracing` (optional), `test` (for TestQueue)
@@ -50,7 +51,7 @@ cargo install hammerwork-web --features postgres
5051

5152
# Or add to your project
5253
[dependencies]
53-
hammerwork-web = { version = "1.2", features = ["postgres"] }
54+
hammerwork-web = { version = "1.3", features = ["postgres"] }
5455
```
5556
5657
Start the dashboard:
@@ -71,6 +72,7 @@ See the [Quick Start Guide](docs/quick-start.md) for complete examples with Post
7172
- **[Web Dashboard](hammerwork-web/README.md)** - Real-time web interface for queue monitoring and job management
7273
- **[Job Tracing & Correlation](docs/tracing.md)** - Distributed tracing, correlation IDs, and OpenTelemetry integration
7374
- **[Job Dependencies & Workflows](docs/workflows.md)** - Complex pipelines, job dependencies, and orchestration
75+
- **[Job Archiving & Retention](docs/archiving.md)** - Policy-driven archival, compression, and compliance management
7476
- **[Job Types & Configuration](docs/job-types.md)** - Job creation, priorities, timeouts, cron jobs
7577
- **[Worker Configuration](docs/worker-configuration.md)** - Worker setup, rate limiting, statistics
7678
- **[Cron Scheduling](docs/cron-scheduling.md)** - Recurring jobs with timezone support
@@ -275,6 +277,65 @@ async fn test_delayed_job_processing() {
275277
276278
The `TestQueue` provides complete compatibility with the `DatabaseQueue` trait while offering deterministic time control through `MockClock`, making it perfect for testing complex workflows, retry logic, and time-dependent job processing.
277279
280+
## Job Archiving Example
281+
282+
Configure automatic job archival for compliance and database performance:
283+
284+
```rust
285+
use hammerwork::{
286+
archive::{ArchivalPolicy, ArchivalConfig, ArchivalReason},
287+
queue::DatabaseQueue
288+
};
289+
use chrono::Duration;
290+
291+
// Configure archival policy
292+
let policy = ArchivalPolicy::new()
293+
.archive_completed_after(Duration::days(7)) // Archive completed jobs after 7 days
294+
.archive_failed_after(Duration::days(30)) // Keep failed jobs for 30 days
295+
.archive_dead_after(Duration::days(14)) // Archive dead jobs after 14 days
296+
.archive_timed_out_after(Duration::days(21)) // Archive timed out jobs after 21 days
297+
.purge_archived_after(Duration::days(365)) // Purge archived jobs after 1 year
298+
.compress_archived_payloads(true) // Enable gzip compression
299+
.with_batch_size(1000) // Process up to 1000 jobs per batch
300+
.enabled(true);
301+
302+
let config = ArchivalConfig::new()
303+
.with_compression_level(6) // Balanced compression
304+
.with_compression_verification(true); // Verify compression integrity
305+
306+
// Run archival (typically scheduled as a cron job)
307+
let stats = queue.archive_jobs(
308+
Some("payment_queue"), // Optional: archive specific queue
309+
&policy,
310+
&config,
311+
ArchivalReason::Automatic, // Automatic, Manual, Compliance, Maintenance
312+
Some("scheduler") // Who initiated the archival
313+
).await?;
314+
315+
println!("Archived {} jobs, saved {} bytes (compression ratio: {:.2})",
316+
stats.jobs_archived,
317+
stats.bytes_archived,
318+
stats.compression_ratio
319+
);
320+
321+
// Restore an archived job if needed
322+
let job = queue.restore_archived_job(job_id).await?;
323+
324+
// List archived jobs with filtering
325+
let archived_jobs = queue.list_archived_jobs(
326+
Some("payment_queue"), // Optional queue filter
327+
Some(100), // Limit
328+
Some(0) // Offset for pagination
329+
).await?;
330+
331+
// Purge old archived jobs for GDPR compliance
332+
let purged = queue.purge_archived_jobs(
333+
Utc::now() - Duration::days(730) // Delete jobs archived over 2 years ago
334+
).await?;
335+
```
336+
337+
Archival moves completed/failed jobs to a separate table with compressed payloads, reducing the main table size while maintaining compliance requirements.
338+
278339
## Web Dashboard
279340
280341
Start the real-time web dashboard for monitoring and managing your job queues:
@@ -344,11 +405,12 @@ queue.enqueue(job).await?;
344405
345406
Hammerwork uses optimized tables with comprehensive indexing:
346407
- **`hammerwork_jobs`** - Main job table with priorities, timeouts, cron scheduling, retry strategies, result storage, and distributed tracing fields
408+
- **`hammerwork_jobs_archive`** - Archive table for completed/failed jobs with compressed payloads (v1.3.0+)
347409
- **`hammerwork_batches`** - Batch metadata and tracking (v0.7.0+)
348410
- **`hammerwork_job_results`** - Job result storage with TTL and expiration (v0.8.0+)
349411
- **`hammerwork_migrations`** - Migration tracking for schema evolution
350412
351-
The schema supports all features including job prioritization, advanced retry strategies, timeouts, cron scheduling, batch processing, result storage with TTL, distributed tracing with trace/correlation IDs, worker autoscaling, and comprehensive lifecycle tracking. See [Database Migrations](docs/migrations.md) for details.
413+
The schema supports all features including job prioritization, advanced retry strategies, timeouts, cron scheduling, batch processing, result storage with TTL, distributed tracing with trace/correlation IDs, worker autoscaling, job archival with compression, and comprehensive lifecycle tracking. See [Database Migrations](docs/migrations.md) for details.
352414
353415
## Development
354416

ROADMAP.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@ This roadmap outlines planned features for Hammerwork, prioritized by impact lev
55
## Phase 2: Medium Impact, Variable Complexity
66
*Valuable features for specific use cases or operational efficiency*
77

8-
### 🗄️ Job Archiving & Retention
9-
**Impact: Medium** | **Complexity: Medium** | **Priority: Medium**
10-
11-
Important for compliance and database performance in high-volume systems.
12-
13-
```rust
14-
// Automatic job archiving
15-
let archival_policy = ArchivalPolicy::new()
16-
.archive_completed_after(Duration::from_days(7))
17-
.archive_failed_after(Duration::from_days(30))
18-
.purge_archived_after(Duration::from_days(365))
19-
.compress_archived_payloads(true);
20-
21-
queue.set_archival_policy(archival_policy).await?;
22-
```
23-
24-
258
### ⚡ Dynamic Job Spawning
269
**Impact: Medium** | **Complexity: Medium-High** | **Priority: Medium**
2710

@@ -57,6 +40,37 @@ let event_stream = EventStream::new()
5740
.with_filtering(|event| event.priority >= JobPriority::High);
5841
```
5942

43+
### 📡 Real-time Archive WebSocket Events
44+
**Impact: Low-Medium** | **Complexity: Low** | **Priority: Low**
45+
46+
Enhance the web dashboard with real-time updates for archive operations.
47+
48+
```rust
49+
// WebSocket events for archive operations
50+
#[derive(Serialize)]
51+
enum ArchiveEvent {
52+
JobArchived { job_id: JobId, queue: String, reason: ArchivalReason },
53+
JobRestored { job_id: JobId, queue: String, restored_by: Option<String> },
54+
BulkArchiveStarted { operation_id: String, estimated_jobs: u64 },
55+
BulkArchiveProgress { operation_id: String, jobs_processed: u64, total: u64 },
56+
BulkArchiveCompleted { operation_id: String, stats: ArchivalStats },
57+
JobsPurged { count: u64, older_than: DateTime<Utc> },
58+
}
59+
60+
// Real-time dashboard updates
61+
websocket.send_event(ArchiveEvent::JobArchived {
62+
job_id: job.id,
63+
queue: job.queue_name.clone(),
64+
reason: ArchivalReason::Automatic,
65+
});
66+
```
67+
68+
**Benefits:**
69+
- Live archive operation progress tracking
70+
- Instant UI updates when jobs are archived/restored
71+
- Real-time compression ratio and storage statistics
72+
- Enhanced user experience during bulk operations
73+
6074
## Phase 3: Specialized Features
6175
*Features for specific enterprise or compliance requirements*
6276

@@ -147,22 +161,16 @@ let geo_config = GeoReplicationConfig::new()
147161

148162
Features are ordered within each phase by priority and should generally be implemented in the following sequence:
149163

150-
**Phase 1 (Advanced Features) - CURRENT PRIORITIES**
151-
1. ✅ Job Dependencies & Workflows (COMPLETED v1.1.0)
152-
2. 🚧 Admin Dashboard & CLI Tools (CLI completed v1.1.0, Web Dashboard remaining)
153-
154-
**Phase 2 (Operational Features)**
155-
1. Job Archiving & Retention
156-
2. Job Testing & Simulation
157-
3. Dynamic Job Spawning
158-
4. Webhook & Event Streaming
164+
**Phase 1 (Operational Features)**
165+
1. Dynamic Job Spawning
166+
2. Webhook & Event Streaming
159167

160-
**Phase 3 (Enterprise Features)**
168+
**Phase 2 (Enterprise Features)**
161169
1. Job Encryption & PII Protection
162170
2. Access Control & Auditing
163171
3. Message Queue Integration
164172

165-
**Phase 4 (Scaling Features)**
173+
**Phase 3 (Scaling Features)**
166174
1. Zero-downtime Deployments
167175
2. Queue Partitioning & Sharding
168176
3. Multi-region Support

0 commit comments

Comments
 (0)