Skip to content

Commit 935b7d8

Browse files
CodingAnarchyclaude
andcommitted
feat: Implement Clone trait for JobQueue structs v1.8.1
- Add manual Clone implementation for JobQueue<DB> to handle generic database types - Fix clippy warnings by removing unnecessary .clone() calls on Copy types (JobStatus) - Add comprehensive test for Clone trait functionality - Update crate version to 1.8.1 - Improve developer ergonomics when sharing queue instances across components 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent a6e91e7 commit 935b7d8

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ 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.8.1] - 2025-07-12
9+
10+
### Added
11+
- **🔄 Clone Trait Implementation**
12+
- Implemented `Clone` trait for `JobQueue<DB>` struct for better ergonomics
13+
- Added manual `Clone` implementation to handle generic database types
14+
- `TestQueue` already had `Clone` support (no changes needed)
15+
- Improved developer experience when sharing queue instances across application components
16+
17+
### Fixed
18+
- **🐛 Code Quality Improvements**
19+
- Fixed unnecessary `.clone()` calls on `JobStatus` enum (implements `Copy`)
20+
- Resolved clippy warnings related to `clone_on_copy`
21+
- Enhanced code efficiency by using copy semantics where appropriate
22+
823
## [1.8.0] - 2025-07-07
924

1025
### Added

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
resolver = "2"
1010

1111
[workspace.package]
12-
version = "1.8.0"
12+
version = "1.8.1"
1313
edition = "2024"
1414
license = "MIT"
1515
repository = "https://github.com/CodingAnarchy/hammerwork"

src/queue/mod.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,16 @@ pub struct JobQueue<DB: Database> {
507507
pub(crate) throttle_configs: Arc<RwLock<HashMap<String, ThrottleConfig>>>,
508508
}
509509

510+
impl<DB: Database> Clone for JobQueue<DB> {
511+
fn clone(&self) -> Self {
512+
Self {
513+
pool: self.pool.clone(),
514+
_phantom: PhantomData,
515+
throttle_configs: self.throttle_configs.clone(),
516+
}
517+
}
518+
}
519+
510520
impl<DB: Database> JobQueue<DB> {
511521
/// Creates a new job queue with the given database connection pool.
512522
///
@@ -762,4 +772,34 @@ mod tests {
762772
assert_eq!(default_config.rate_per_minute, None);
763773
assert!(default_config.enabled);
764774
}
775+
776+
#[test]
777+
fn test_job_queue_clone() {
778+
// Test that JobQueue implements Clone trait correctly
779+
// This test verifies compilation and basic cloning functionality
780+
781+
#[cfg(feature = "test")]
782+
{
783+
use crate::queue::test::TestQueue;
784+
785+
// Test that TestQueue can be cloned
786+
let test_queue = TestQueue::new();
787+
let cloned_queue = test_queue.clone();
788+
789+
// Basic verification - both should be independent instances
790+
// (This is mainly a compilation test to ensure Clone trait is properly implemented)
791+
let _ = test_queue;
792+
let _ = cloned_queue;
793+
}
794+
795+
// Test that JobQueue<DB> implements Clone at the type level
796+
// This function will only compile if JobQueue<DB> implements Clone
797+
#[allow(dead_code)]
798+
fn _test_job_queue_clone_trait<DB: sqlx::Database>()
799+
-> impl Fn(&JobQueue<DB>) -> JobQueue<DB> {
800+
|queue: &JobQueue<DB>| queue.clone()
801+
}
802+
803+
// If we reach this point, Clone is properly implemented
804+
}
765805
}

src/queue/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl TestStorage {
279279
/// Add a job to the appropriate queue and status list
280280
fn add_job_to_queue(&mut self, job: &Job) {
281281
let queue_jobs = self.queues.entry(job.queue_name.clone()).or_default();
282-
let status_jobs = queue_jobs.entry(job.status.clone()).or_default();
282+
let status_jobs = queue_jobs.entry(job.status).or_default();
283283
if !status_jobs.contains(&job.id) {
284284
status_jobs.push(job.id);
285285
}
@@ -291,7 +291,7 @@ impl TestStorage {
291291
let old_status = self
292292
.jobs
293293
.get(&job_id)
294-
.map(|job| job.status.clone())
294+
.map(|job| job.status)
295295
.ok_or_else(|| HammerworkError::JobNotFound {
296296
id: job_id.to_string(),
297297
})?;
@@ -314,7 +314,7 @@ impl TestStorage {
314314

315315
// Update the job status
316316
if let Some(job) = self.jobs.get_mut(&job_id) {
317-
job.status = new_status.clone();
317+
job.status = new_status;
318318
}
319319

320320
// Add to new status
@@ -2219,7 +2219,7 @@ impl DatabaseQueue for TestQueue {
22192219
archived_jobs.push(crate::archive::ArchivedJob {
22202220
id: job.id,
22212221
queue_name: job.queue_name.clone(),
2222-
status: job.status.clone(),
2222+
status: job.status,
22232223
created_at: job.created_at,
22242224
archived_at: now, // Mock archived time
22252225
archival_reason: crate::archive::ArchivalReason::Manual, // Mock reason

0 commit comments

Comments
 (0)