7979//! ```
8080
8181use super :: {
82- with_filters , with_pagination , with_sort , ApiResponse , FilterParams ,
83- PaginatedResponse , PaginationMeta , PaginationParams , SortParams ,
82+ ApiResponse , FilterParams , PaginatedResponse , PaginationMeta , PaginationParams , SortParams ,
83+ with_filters , with_pagination , with_sort ,
8484} ;
8585use hammerwork:: queue:: DatabaseQueue ;
8686use serde:: { Deserialize , Serialize } ;
@@ -226,29 +226,27 @@ where
226226 // For now, return a placeholder response
227227 // In a real implementation, this would query the database with filters and pagination
228228 let _ = ( queue, filters, sort) ;
229-
230- let mock_jobs = vec ! [
231- JobInfo {
232- id: "job-1" . to_string( ) ,
233- queue_name: "default" . to_string( ) ,
234- status: "pending" . to_string( ) ,
235- priority: "normal" . to_string( ) ,
236- attempts: 0 ,
237- max_attempts: 3 ,
238- payload
: serde_json
:: json!
( { "task" : "send_email" , "to" : "[email protected] " } ) , 239- created_at: chrono:: Utc :: now( ) ,
240- scheduled_at: chrono:: Utc :: now( ) ,
241- started_at: None ,
242- completed_at: None ,
243- failed_at: None ,
244- error_message: None ,
245- processing_time_ms: None ,
246- cron_schedule: None ,
247- is_recurring: false ,
248- trace_id: None ,
249- correlation_id: None ,
250- } ,
251- ] ;
229+
230+ let mock_jobs = vec ! [ JobInfo {
231+ id: "job-1" . to_string( ) ,
232+ queue_name: "default" . to_string( ) ,
233+ status: "pending" . to_string( ) ,
234+ priority: "normal" . to_string( ) ,
235+ attempts: 0 ,
236+ max_attempts: 3 ,
237+ payload
: serde_json
:: json!
( { "task" : "send_email" , "to" : "[email protected] " } ) , 238+ created_at: chrono:: Utc :: now( ) ,
239+ scheduled_at: chrono:: Utc :: now( ) ,
240+ started_at: None ,
241+ completed_at: None ,
242+ failed_at: None ,
243+ error_message: None ,
244+ processing_time_ms: None ,
245+ cron_schedule: None ,
246+ is_recurring: false ,
247+ trace_id: None ,
248+ correlation_id: None ,
249+ } ] ;
252250
253251 let response = PaginatedResponse {
254252 items : mock_jobs,
@@ -277,8 +275,7 @@ where
277275 _ => JobPriority :: Normal ,
278276 } ;
279277
280- let mut job = Job :: new ( request. queue_name , request. payload )
281- . with_priority ( priority) ;
278+ let mut job = Job :: new ( request. queue_name , request. payload ) . with_priority ( priority) ;
282279
283280 if let Some ( scheduled_at) = request. scheduled_at {
284281 job. scheduled_at = scheduled_at;
@@ -312,10 +309,7 @@ where
312309}
313310
314311/// Handler for getting a specific job
315- async fn get_job_handler < T > (
316- job_id : String ,
317- queue : Arc < T > ,
318- ) -> Result < impl Reply , warp:: Rejection >
312+ async fn get_job_handler < T > ( job_id : String , queue : Arc < T > ) -> Result < impl Reply , warp:: Rejection >
319313where
320314 T : DatabaseQueue + Send + Sync ,
321315{
@@ -343,10 +337,12 @@ where
343337 completed_at : job. completed_at ,
344338 failed_at : job. failed_at ,
345339 error_message : job. error_message . clone ( ) ,
346- processing_time_ms : job. started_at . and_then ( |start|
347- job. completed_at . or ( job. failed_at ) . or ( job. timed_out_at )
340+ processing_time_ms : job. started_at . and_then ( |start| {
341+ job. completed_at
342+ . or ( job. failed_at )
343+ . or ( job. timed_out_at )
348344 . map ( |end| ( end - start) . num_milliseconds ( ) )
349- ) ,
345+ } ) ,
350346 cron_schedule : job. cron_schedule . clone ( ) ,
351347 is_recurring : job. is_recurring ( ) ,
352348 trace_id : job. trace_id . clone ( ) ,
@@ -384,36 +380,33 @@ where
384380 } ;
385381
386382 match action_request. action . as_str ( ) {
387- "retry" => {
388- match queue. retry_job ( job_uuid, chrono:: Utc :: now ( ) ) . await {
389- Ok ( ( ) ) => {
390- let response = ApiResponse :: success ( serde_json:: json!( {
391- "message" : format!( "Job '{}' scheduled for retry" , job_id)
392- } ) ) ;
393- Ok ( warp:: reply:: json ( & response) )
394- }
395- Err ( e) => {
396- let response = ApiResponse :: < ( ) > :: error ( format ! ( "Failed to retry job: {}" , e) ) ;
397- Ok ( warp:: reply:: json ( & response) )
398- }
383+ "retry" => match queue. retry_job ( job_uuid, chrono:: Utc :: now ( ) ) . await {
384+ Ok ( ( ) ) => {
385+ let response = ApiResponse :: success ( serde_json:: json!( {
386+ "message" : format!( "Job '{}' scheduled for retry" , job_id)
387+ } ) ) ;
388+ Ok ( warp:: reply:: json ( & response) )
399389 }
400- }
401- "cancel" | "delete" => {
402- match queue. delete_job ( job_uuid) . await {
403- Ok ( ( ) ) => {
404- let response = ApiResponse :: success ( serde_json:: json!( {
405- "message" : format!( "Job '{}' deleted" , job_id)
406- } ) ) ;
407- Ok ( warp:: reply:: json ( & response) )
408- }
409- Err ( e) => {
410- let response = ApiResponse :: < ( ) > :: error ( format ! ( "Failed to delete job: {}" , e) ) ;
411- Ok ( warp:: reply:: json ( & response) )
412- }
390+ Err ( e) => {
391+ let response = ApiResponse :: < ( ) > :: error ( format ! ( "Failed to retry job: {}" , e) ) ;
392+ Ok ( warp:: reply:: json ( & response) )
413393 }
414- }
394+ } ,
395+ "cancel" | "delete" => match queue. delete_job ( job_uuid) . await {
396+ Ok ( ( ) ) => {
397+ let response = ApiResponse :: success ( serde_json:: json!( {
398+ "message" : format!( "Job '{}' deleted" , job_id)
399+ } ) ) ;
400+ Ok ( warp:: reply:: json ( & response) )
401+ }
402+ Err ( e) => {
403+ let response = ApiResponse :: < ( ) > :: error ( format ! ( "Failed to delete job: {}" , e) ) ;
404+ Ok ( warp:: reply:: json ( & response) )
405+ }
406+ } ,
415407 _ => {
416- let response = ApiResponse :: < ( ) > :: error ( format ! ( "Unknown action: {}" , action_request. action) ) ;
408+ let response =
409+ ApiResponse :: < ( ) > :: error ( format ! ( "Unknown action: {}" , action_request. action) ) ;
417410 Ok ( warp:: reply:: json ( & response) )
418411 }
419412 }
@@ -503,7 +496,7 @@ mod tests {
503496 "priority": "high",
504497 "max_attempts": 5
505498 }"# ;
506-
499+
507500 let request: CreateJobRequest = serde_json:: from_str ( json) . unwrap ( ) ;
508501 assert_eq ! ( request. queue_name, "email" ) ;
509502 assert_eq ! ( request. priority, Some ( "high" . to_string( ) ) ) ;
@@ -525,9 +518,9 @@ mod tests {
525518 "action": "delete",
526519 "reason": "Cleanup old jobs"
527520 }"# ;
528-
521+
529522 let request: BulkJobActionRequest = serde_json:: from_str ( json) . unwrap ( ) ;
530523 assert_eq ! ( request. job_ids. len( ) , 3 ) ;
531524 assert_eq ! ( request. action, "delete" ) ;
532525 }
533- }
526+ }
0 commit comments