@@ -32,6 +32,19 @@ pub struct StatusUpdate {
3232 pub finished : bool ,
3333 pub message : & ' static str ,
3434 pub percent_done : f64 ,
35+ pub status_type : StatusType ,
36+ }
37+
38+ #[ derive( Debug , Serialize ) ]
39+ #[ serde( rename_all = "kebab-case" ) ]
40+ pub enum StatusType {
41+ Downloading ,
42+ Compressing ,
43+ Extracting ,
44+ Processing ,
45+ Sending ,
46+ WaitingForResults ,
47+ Finished ,
3548}
3649
3750// compatible with anyhow
@@ -126,12 +139,18 @@ impl TmcCore {
126139 self . progress_report = Some ( Box :: new ( progress_report) ) ;
127140 }
128141
129- pub fn report_progress ( & self , message : & ' static str , percent_done : f64 ) {
142+ pub fn report_progress (
143+ & self ,
144+ message : & ' static str ,
145+ status_type : StatusType ,
146+ percent_done : f64 ,
147+ ) {
130148 self . progress_report . as_ref ( ) . map ( |f| {
131149 f ( StatusUpdate {
132150 finished : false ,
133151 message,
134152 percent_done,
153+ status_type,
135154 } )
136155 } ) ;
137156 }
@@ -142,6 +161,7 @@ impl TmcCore {
142161 finished : true ,
143162 message,
144163 percent_done : 1.0 ,
164+ status_type : StatusType :: Finished ,
145165 } )
146166 } ) ;
147167 }
@@ -242,11 +262,11 @@ impl TmcCore {
242262 // TODO: do in memory without zip_file?
243263 let zip_file = NamedTempFile :: new ( ) . map_err ( CoreError :: TempFile ) ?;
244264
245- self . report_progress ( "Downloading exercise..." , progress) ;
265+ self . report_progress ( "Downloading exercise..." , StatusType :: Downloading , progress) ;
246266 self . download_exercise ( exercise_id, zip_file. path ( ) ) ?;
247267 progress += step;
248268
249- self . report_progress ( "Extracting exercise..." , progress) ;
269+ self . report_progress ( "Extracting exercise..." , StatusType :: Extracting , progress) ;
250270 task_executor:: extract_project ( zip_file. path ( ) , target) ?;
251271 progress += step;
252272 }
@@ -406,14 +426,30 @@ impl TmcCore {
406426 locale : Option < Language > ,
407427 ) -> Result < NewSubmission > {
408428 // compress
409- self . report_progress ( "Submitting exercise. Compressing submission..." , 0.0 ) ;
429+ self . report_progress (
430+ "Submitting exercise. Compressing submission..." ,
431+ StatusType :: Compressing ,
432+ 0.0 ,
433+ ) ;
410434 let compressed = task_executor:: compress_project ( submission_path) ?;
411- self . report_progress ( "Compressed submission. Creating temporary file..." , 0.25 ) ;
435+ self . report_progress (
436+ "Compressed submission. Creating temporary file..." ,
437+ StatusType :: Processing ,
438+ 0.25 ,
439+ ) ;
412440 let mut file = NamedTempFile :: new ( ) . map_err ( CoreError :: TempFile ) ?;
413- self . report_progress ( "Created temporary file. Writing compressed data..." , 0.5 ) ;
441+ self . report_progress (
442+ "Created temporary file. Writing compressed data..." ,
443+ StatusType :: Processing ,
444+ 0.5 ,
445+ ) ;
414446 file. write_all ( & compressed)
415447 . map_err ( |e| CoreError :: FileWrite ( file. path ( ) . to_path_buf ( ) , e) ) ?;
416- self . report_progress ( "Wrote compressed data. Posting submission..." , 0.75 ) ;
448+ self . report_progress (
449+ "Wrote compressed data. Posting submission..." ,
450+ StatusType :: Sending ,
451+ 0.75 ,
452+ ) ;
417453
418454 let result = self . post_submission ( submission_url, file. path ( ) , locale) ;
419455 self . report_complete ( "Submission finished!" ) ;
@@ -444,13 +480,21 @@ impl TmcCore {
444480 ( _, status) => {
445481 // new status, update progress
446482 match status {
447- SandboxStatus :: Created => self . report_progress ( "Created" , 0.25 ) ,
448- SandboxStatus :: SendingToSandbox => {
449- self . report_progress ( "Sending to sandbox" , 0.5 )
450- }
451- SandboxStatus :: ProcessingOnSandbox => {
452- self . report_progress ( "Processing on sandbox" , 0.75 )
453- }
483+ SandboxStatus :: Created => self . report_progress (
484+ "Created" ,
485+ StatusType :: WaitingForResults ,
486+ 0.25 ,
487+ ) ,
488+ SandboxStatus :: SendingToSandbox => self . report_progress (
489+ "Sending to sandbox" ,
490+ StatusType :: WaitingForResults ,
491+ 0.5 ,
492+ ) ,
493+ SandboxStatus :: ProcessingOnSandbox => self . report_progress (
494+ "Processing on sandbox" ,
495+ StatusType :: WaitingForResults ,
496+ 0.75 ,
497+ ) ,
454498 }
455499 previous_status = Some ( status) ;
456500 }
@@ -1151,18 +1195,20 @@ mod test {
11511195 finished : false ,
11521196 message : "submitting..." ,
11531197 percent_done : 0.5 ,
1198+ status_type : StatusType :: Sending ,
11541199 } ;
11551200 assert_eq ! (
1156- r#"{"finished":false,"message":"submitting...","percent_done":0.5}"# ,
1201+ r#"{"finished":false,"message":"submitting...","percent_done":0.5,"status_type":"sending" }"# ,
11571202 serde_json:: to_string( & p) . unwrap( )
11581203 ) ;
11591204 let f = StatusUpdate {
11601205 finished : true ,
11611206 message : "done" ,
11621207 percent_done : 1.0 ,
1208+ status_type : StatusType :: Finished ,
11631209 } ;
11641210 assert_eq ! (
1165- r#"{"finished":true,"message":"done","percent_done":1.0}"# ,
1211+ r#"{"finished":true,"message":"done","percent_done":1.0,"status_type":"finished" }"# ,
11661212 serde_json:: to_string( & f) . unwrap( )
11671213 ) ;
11681214 }
0 commit comments