@@ -1082,10 +1082,11 @@ where
10821082 ///
10831083 /// # Examples
10841084 ///
1085- /// ```rust
1085+ /// ```rust,no_run
10861086 /// # use hammerwork::{Worker, worker::{JobEventHooks, JobHookEvent}};
10871087 /// # use std::sync::Arc;
1088- /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await.unwrap()));
1088+ /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1089+ /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await?));
10891090 /// # let handler: hammerwork::worker::JobHandler = Arc::new(|job| Box::pin(async move { Ok(()) }));
10901091 ///
10911092 /// let hooks = JobEventHooks::new()
@@ -1105,6 +1106,8 @@ where
11051106 ///
11061107 /// let worker = Worker::new(queue, "traced_queue".to_string(), handler)
11071108 /// .with_event_hooks(hooks);
1109+ /// # Ok(())
1110+ /// # }
11081111 /// ```
11091112 pub fn with_event_hooks ( mut self , hooks : JobEventHooks ) -> Self {
11101113 self . event_hooks = hooks;
@@ -1122,16 +1125,19 @@ where
11221125 ///
11231126 /// # Examples
11241127 ///
1125- /// ```rust
1128+ /// ```rust,no_run
11261129 /// # use hammerwork::Worker;
11271130 /// # use std::sync::Arc;
1128- /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await.unwrap()));
1131+ /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1132+ /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await?));
11291133 /// # let handler: hammerwork::worker::JobHandler = Arc::new(|job| Box::pin(async move { Ok(()) }));
11301134 ///
11311135 /// let worker = Worker::new(queue, "queue".to_string(), handler)
11321136 /// .on_job_start(|event| {
11331137 /// println!("Starting job: {}", event.job.id);
11341138 /// });
1139+ /// # Ok(())
1140+ /// # }
11351141 /// ```
11361142 pub fn on_job_start < F > ( mut self , handler : F ) -> Self
11371143 where
@@ -1149,10 +1155,11 @@ where
11491155 ///
11501156 /// # Examples
11511157 ///
1152- /// ```rust
1158+ /// ```rust,no_run
11531159 /// # use hammerwork::Worker;
11541160 /// # use std::sync::Arc;
1155- /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await.unwrap()));
1161+ /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1162+ /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await?));
11561163 /// # let handler: hammerwork::worker::JobHandler = Arc::new(|job| Box::pin(async move { Ok(()) }));
11571164 ///
11581165 /// let worker = Worker::new(queue, "queue".to_string(), handler)
@@ -1161,6 +1168,8 @@ where
11611168 /// println!("Job {} completed in {:?}", event.job.id, duration);
11621169 /// }
11631170 /// });
1171+ /// # Ok(())
1172+ /// # }
11641173 /// ```
11651174 pub fn on_job_complete < F > ( mut self , handler : F ) -> Self
11661175 where
@@ -1178,10 +1187,11 @@ where
11781187 ///
11791188 /// # Examples
11801189 ///
1181- /// ```rust
1190+ /// ```rust,no_run
11821191 /// # use hammerwork::Worker;
11831192 /// # use std::sync::Arc;
1184- /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await.unwrap()));
1193+ /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1194+ /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await?));
11851195 /// # let handler: hammerwork::worker::JobHandler = Arc::new(|job| Box::pin(async move { Ok(()) }));
11861196 ///
11871197 /// let worker = Worker::new(queue, "queue".to_string(), handler)
@@ -1190,6 +1200,8 @@ where
11901200 /// eprintln!("Job {} failed: {}", event.job.id, error);
11911201 /// }
11921202 /// });
1203+ /// # Ok(())
1204+ /// # }
11931205 /// ```
11941206 pub fn on_job_fail < F > ( mut self , handler : F ) -> Self
11951207 where
@@ -1207,16 +1219,19 @@ where
12071219 ///
12081220 /// # Examples
12091221 ///
1210- /// ```rust
1222+ /// ```rust,no_run
12111223 /// # use hammerwork::Worker;
12121224 /// # use std::sync::Arc;
1213- /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await.unwrap()));
1225+ /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1226+ /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await?));
12141227 /// # let handler: hammerwork::worker::JobHandler = Arc::new(|job| Box::pin(async move { Ok(()) }));
12151228 ///
12161229 /// let worker = Worker::new(queue, "queue".to_string(), handler)
12171230 /// .on_job_timeout(|event| {
12181231 /// println!("Job {} timed out after {:?}", event.job.id, event.duration);
12191232 /// });
1233+ /// # Ok(())
1234+ /// # }
12201235 /// ```
12211236 pub fn on_job_timeout < F > ( mut self , handler : F ) -> Self
12221237 where
@@ -1234,16 +1249,19 @@ where
12341249 ///
12351250 /// # Examples
12361251 ///
1237- /// ```rust
1252+ /// ```rust,no_run
12381253 /// # use hammerwork::Worker;
12391254 /// # use std::sync::Arc;
1240- /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await.unwrap()));
1255+ /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1256+ /// # let queue = Arc::new(hammerwork::JobQueue::new(sqlx::PgPool::connect("").await?));
12411257 /// # let handler: hammerwork::worker::JobHandler = Arc::new(|job| Box::pin(async move { Ok(()) }));
12421258 ///
12431259 /// let worker = Worker::new(queue, "queue".to_string(), handler)
12441260 /// .on_job_retry(|event| {
12451261 /// println!("Retrying job {} due to: {:?}", event.job.id, event.error);
12461262 /// });
1263+ /// # Ok(())
1264+ /// # }
12471265 /// ```
12481266 pub fn on_job_retry < F > ( mut self , handler : F ) -> Self
12491267 where
@@ -1451,7 +1469,7 @@ where
14511469 span. record ( "error.type" , "timeout" ) ;
14521470 span. record (
14531471 "error.message" ,
1454- & format ! ( "Job timed out after {:?}" , timeout) ,
1472+ format ! ( "Job timed out after {:?}" , timeout) ,
14551473 ) ;
14561474 }
14571475
@@ -2687,8 +2705,10 @@ mod tests {
26872705 #[ test]
26882706 fn test_scaling_decision_logic ( ) {
26892707 // This test simulates the scaling decision logic
2690- let mut metrics = AutoscaleMetrics :: default ( ) ;
2691- metrics. active_workers = 3 ;
2708+ let mut metrics = AutoscaleMetrics {
2709+ active_workers : 3 ,
2710+ ..Default :: default ( )
2711+ } ;
26922712
26932713 let config = AutoscaleConfig :: default ( ) ;
26942714
@@ -2735,14 +2755,13 @@ mod tests {
27352755 #[ test]
27362756 fn test_queue_depth_averaging ( ) {
27372757 let now = Utc :: now ( ) ;
2738- let mut history = Vec :: new ( ) ;
2739-
2740- // Add some history entries
2741- history. push ( ( now - chrono:: Duration :: seconds ( 25 ) , 10 ) ) ;
2742- history. push ( ( now - chrono:: Duration :: seconds ( 20 ) , 8 ) ) ;
2743- history. push ( ( now - chrono:: Duration :: seconds ( 15 ) , 12 ) ) ;
2744- history. push ( ( now - chrono:: Duration :: seconds ( 10 ) , 6 ) ) ;
2745- history. push ( ( now - chrono:: Duration :: seconds ( 5 ) , 14 ) ) ;
2758+ let history = vec ! [
2759+ ( now - chrono:: Duration :: seconds( 25 ) , 10 ) ,
2760+ ( now - chrono:: Duration :: seconds( 20 ) , 8 ) ,
2761+ ( now - chrono:: Duration :: seconds( 15 ) , 12 ) ,
2762+ ( now - chrono:: Duration :: seconds( 10 ) , 6 ) ,
2763+ ( now - chrono:: Duration :: seconds( 5 ) , 14 ) ,
2764+ ] ;
27462765
27472766 // Calculate average
27482767 let avg =
@@ -2764,10 +2783,10 @@ mod tests {
27642783 #[ test]
27652784 fn test_worker_count_boundaries ( ) {
27662785 let config = AutoscaleConfig :: default ( ) ;
2767- let mut metrics = AutoscaleMetrics :: default ( ) ;
2768-
2769- // Test scaling up to max workers
2770- metrics . active_workers = config . max_workers - 1 ;
2786+ let mut metrics = AutoscaleMetrics {
2787+ active_workers : config . max_workers - 1 ,
2788+ .. Default :: default ( )
2789+ } ;
27712790 let new_count = ( metrics. active_workers + config. scale_step ) . min ( config. max_workers ) ;
27722791 assert_eq ! ( new_count, config. max_workers) ;
27732792
@@ -2813,14 +2832,13 @@ mod tests {
28132832 #[ test]
28142833 fn test_history_cleanup ( ) {
28152834 let now = Utc :: now ( ) ;
2816- let mut history = Vec :: new ( ) ;
2817-
2818- // Add entries with various ages
2819- history. push ( ( now - chrono:: Duration :: seconds ( 60 ) , 10 ) ) ; // Too old
2820- history. push ( ( now - chrono:: Duration :: seconds ( 45 ) , 8 ) ) ; // Too old
2821- history. push ( ( now - chrono:: Duration :: seconds ( 25 ) , 12 ) ) ; // Recent
2822- history. push ( ( now - chrono:: Duration :: seconds ( 15 ) , 6 ) ) ; // Recent
2823- history. push ( ( now - chrono:: Duration :: seconds ( 5 ) , 14 ) ) ; // Recent
2835+ let mut history = vec ! [
2836+ ( now - chrono:: Duration :: seconds( 60 ) , 10 ) , // Too old
2837+ ( now - chrono:: Duration :: seconds( 45 ) , 8 ) , // Too old
2838+ ( now - chrono:: Duration :: seconds( 25 ) , 12 ) , // Recent
2839+ ( now - chrono:: Duration :: seconds( 15 ) , 6 ) , // Recent
2840+ ( now - chrono:: Duration :: seconds( 5 ) , 14 ) , // Recent
2841+ ] ;
28242842
28252843 // Filter based on 30-second window
28262844 let evaluation_window = Duration :: from_secs ( 30 ) ;
0 commit comments