@@ -85,7 +85,25 @@ impl JobRow {
85
85
id : uuid:: Uuid :: parse_str ( & self . id ) ?,
86
86
queue_name : self . queue_name ,
87
87
payload : self . payload ,
88
- status : serde_json:: from_str ( & self . status ) ?,
88
+ status : {
89
+ // Handle both quoted (old format) and unquoted (new format) status values
90
+ let cleaned_str = self . status . trim_matches ( '"' ) ;
91
+ match cleaned_str {
92
+ "Pending" => JobStatus :: Pending ,
93
+ "Running" => JobStatus :: Running ,
94
+ "Completed" => JobStatus :: Completed ,
95
+ "Failed" => JobStatus :: Failed ,
96
+ "Dead" => JobStatus :: Dead ,
97
+ "TimedOut" => JobStatus :: TimedOut ,
98
+ "Retrying" => JobStatus :: Retrying ,
99
+ "Archived" => JobStatus :: Archived ,
100
+ _ => {
101
+ return Err ( crate :: error:: HammerworkError :: Processing (
102
+ format ! ( "Unknown job status: {}" , cleaned_str) ,
103
+ ) ) ;
104
+ }
105
+ }
106
+ } ,
89
107
priority : JobPriority :: from_i32 ( self . priority ) . unwrap_or ( JobPriority :: Normal ) ,
90
108
attempts : self . attempts ,
91
109
max_attempts : self . max_attempts ,
@@ -444,7 +462,21 @@ impl DeadJobRow {
444
462
id : uuid:: Uuid :: parse_str ( & self . id ) ?,
445
463
queue_name : self . queue_name ,
446
464
payload : self . payload ,
447
- status : serde_json:: from_str ( & self . status ) . unwrap_or ( JobStatus :: Dead ) ,
465
+ status : {
466
+ // Handle both quoted (old format) and unquoted (new format) status values
467
+ let cleaned_str = self . status . trim_matches ( '"' ) ;
468
+ match cleaned_str {
469
+ "Pending" => JobStatus :: Pending ,
470
+ "Running" => JobStatus :: Running ,
471
+ "Completed" => JobStatus :: Completed ,
472
+ "Failed" => JobStatus :: Failed ,
473
+ "Dead" => JobStatus :: Dead ,
474
+ "TimedOut" => JobStatus :: TimedOut ,
475
+ "Retrying" => JobStatus :: Retrying ,
476
+ "Archived" => JobStatus :: Archived ,
477
+ _ => JobStatus :: Dead , // Default fallback for unknown status
478
+ }
479
+ } ,
448
480
priority : JobPriority :: from_i32 ( self . priority ) . unwrap_or ( JobPriority :: Normal ) ,
449
481
attempts : self . attempts ,
450
482
max_attempts : self . max_attempts ,
@@ -769,7 +801,6 @@ impl DatabaseQueue for crate::queue::JobQueue<MySql> {
769
801
}
770
802
771
803
async fn enqueue_batch ( & self , batch : crate :: batch:: JobBatch ) -> Result < crate :: batch:: BatchId > {
772
- use crate :: batch:: BatchStatus ;
773
804
774
805
// Validate the batch first
775
806
batch. validate ( ) ?;
@@ -790,7 +821,7 @@ impl DatabaseQueue for crate::queue::JobQueue<MySql> {
790
821
. bind ( 0i32 ) // completed_jobs
791
822
. bind ( 0i32 ) // failed_jobs
792
823
. bind ( batch. jobs . len ( ) as i32 ) // pending_jobs
793
- . bind ( serde_json :: to_string ( & BatchStatus :: Pending ) ? )
824
+ . bind ( crate :: batch :: BatchStatus :: Pending )
794
825
. bind ( serde_json:: to_string ( & batch. failure_mode ) ?)
795
826
. bind ( batch. created_at )
796
827
. bind ( serde_json:: to_value ( & batch. metadata ) ?)
@@ -876,7 +907,7 @@ impl DatabaseQueue for crate::queue::JobQueue<MySql> {
876
907
let completed_jobs: i32 = batch_row. get ( "completed_jobs" ) ;
877
908
let failed_jobs: i32 = batch_row. get ( "failed_jobs" ) ;
878
909
let pending_jobs: i32 = batch_row. get ( "pending_jobs" ) ;
879
- let status : String = batch_row. get ( "status" ) ;
910
+ let status_str : String = batch_row. get ( "status" ) ;
880
911
let created_at: DateTime < Utc > = batch_row. get ( "created_at" ) ;
881
912
let completed_at: Option < DateTime < Utc > > = batch_row. get ( "completed_at" ) ;
882
913
let error_summary: Option < String > = batch_row. get ( "error_summary" ) ;
@@ -894,13 +925,30 @@ impl DatabaseQueue for crate::queue::JobQueue<MySql> {
894
925
. filter_map ( |( id_str, error) | uuid:: Uuid :: parse_str ( & id_str) . ok ( ) . map ( |id| ( id, error) ) )
895
926
. collect ( ) ;
896
927
928
+ let status = {
929
+ // Handle both quoted (old format) and unquoted (new format) status values
930
+ let cleaned_str = status_str. trim_matches ( '"' ) ;
931
+ match cleaned_str {
932
+ "Pending" => crate :: batch:: BatchStatus :: Pending ,
933
+ "Processing" => crate :: batch:: BatchStatus :: Processing ,
934
+ "Completed" => crate :: batch:: BatchStatus :: Completed ,
935
+ "PartiallyFailed" => crate :: batch:: BatchStatus :: PartiallyFailed ,
936
+ "Failed" => crate :: batch:: BatchStatus :: Failed ,
937
+ _ => {
938
+ return Err ( crate :: error:: HammerworkError :: Batch {
939
+ message : format ! ( "Unknown batch status: {}" , cleaned_str) ,
940
+ } ) ;
941
+ }
942
+ }
943
+ } ;
944
+
897
945
Ok ( BatchResult {
898
946
batch_id,
899
947
total_jobs : total_jobs as u32 ,
900
948
completed_jobs : completed_jobs as u32 ,
901
949
failed_jobs : failed_jobs as u32 ,
902
950
pending_jobs : pending_jobs as u32 ,
903
- status : serde_json :: from_str ( & status ) ? ,
951
+ status,
904
952
created_at,
905
953
completed_at,
906
954
error_summary,
@@ -2041,7 +2089,7 @@ impl DatabaseQueue for crate::queue::JobQueue<MySql> {
2041
2089
} else {
2042
2090
Some ( serde_json:: to_value ( & job. depends_on ) ?)
2043
2091
} )
2044
- . bind ( serde_json :: to_string ( & job. dependency_status ) ? )
2092
+ . bind ( job. dependency_status . as_str ( ) )
2045
2093
. bind ( serde_json:: to_value ( & job. result_config ) ?)
2046
2094
. bind ( job. trace_id )
2047
2095
. bind ( job. correlation_id )
@@ -2255,8 +2303,22 @@ impl DatabaseQueue for crate::queue::JobQueue<MySql> {
2255
2303
archived_jobs. push ( ArchivedJob {
2256
2304
id : uuid:: Uuid :: parse_str ( & row. get :: < String , _ > ( "id" ) ) ?,
2257
2305
queue_name : row. get ( "queue_name" ) ,
2258
- status : serde_json:: from_str :: < JobStatus > ( & row. get :: < String , _ > ( "status" ) )
2259
- . unwrap_or ( JobStatus :: Dead ) ,
2306
+ status : {
2307
+ // Handle both quoted (old format) and unquoted (new format) status values
2308
+ let status_str: String = row. get ( "status" ) ;
2309
+ let cleaned_str = status_str. trim_matches ( '"' ) ;
2310
+ match cleaned_str {
2311
+ "Pending" => JobStatus :: Pending ,
2312
+ "Running" => JobStatus :: Running ,
2313
+ "Completed" => JobStatus :: Completed ,
2314
+ "Failed" => JobStatus :: Failed ,
2315
+ "Dead" => JobStatus :: Dead ,
2316
+ "TimedOut" => JobStatus :: TimedOut ,
2317
+ "Retrying" => JobStatus :: Retrying ,
2318
+ "Archived" => JobStatus :: Archived ,
2319
+ _ => JobStatus :: Dead , // Default fallback for unknown status
2320
+ }
2321
+ } ,
2260
2322
created_at : row. get ( "created_at" ) ,
2261
2323
archived_at : row. get ( "archived_at" ) ,
2262
2324
archival_reason : serde_json:: from_str ( & row. get :: < String , _ > ( "archival_reason" ) )
@@ -2464,7 +2526,7 @@ impl crate::queue::JobQueue<sqlx::MySql> {
2464
2526
} else {
2465
2527
Some ( serde_json:: to_value ( & job. dependents ) ?)
2466
2528
} )
2467
- . bind ( serde_json :: to_string ( & job. dependency_status ) ? )
2529
+ . bind ( job. dependency_status . as_str ( ) )
2468
2530
. bind ( job. workflow_id . map ( |id| id. to_string ( ) ) )
2469
2531
. bind ( job. workflow_name )
2470
2532
. bind ( job. trace_id )
0 commit comments