@@ -356,19 +356,16 @@ impl TmcClient {
356
356
api_v8:: submission:: get_exercise_submissions_for_current_user ( self , exercise_id)
357
357
}
358
358
359
- /// Waits for a submission to finish. May require authentication.
360
- ///
361
- /// # Errors
362
- /// If authentication is required but the client is not authenticated, there's some problem reaching the API, or if the API returns an error.
363
- pub fn wait_for_submission (
359
+ // abstracts waiting for submission over different functions for getting the submission status
360
+ fn wait_for_submission_inner (
364
361
& self ,
365
- submission_url : & str ,
362
+ f : impl Fn ( ) -> Result < SubmissionProcessingStatus , ClientError > ,
366
363
) -> Result < SubmissionFinished , ClientError > {
367
364
start_stage ( 4 , "Waiting for submission" , None ) ;
368
365
369
366
let mut previous_status = None ;
370
367
loop {
371
- match self . check_submission ( submission_url ) ? {
368
+ match f ( ) ? {
372
369
SubmissionProcessingStatus :: Finished ( f) => {
373
370
finish_stage ( "Submission finished processing!" , None ) ;
374
371
return Ok ( * f) ;
@@ -435,6 +432,24 @@ impl TmcClient {
435
432
}
436
433
}
437
434
435
+ pub fn wait_for_submission_at (
436
+ & self ,
437
+ submission_url : Url ,
438
+ ) -> Result < SubmissionFinished , ClientError > {
439
+ self . wait_for_submission_inner ( || api_v8:: get_json ( self , submission_url. clone ( ) , & [ ] ) )
440
+ }
441
+
442
+ /// Waits for a submission to finish. May require authentication.
443
+ ///
444
+ /// # Errors
445
+ /// If authentication is required but the client is not authenticated, there's some problem reaching the API, or if the API returns an error.
446
+ pub fn wait_for_submission (
447
+ & self ,
448
+ submission_id : u32 ,
449
+ ) -> Result < SubmissionFinished , ClientError > {
450
+ self . wait_for_submission_inner ( || api_v8:: get_submission ( self , submission_id) )
451
+ }
452
+
438
453
/// Fetches the course's exercises from the server,
439
454
/// and finds new or updated exercises. Requires authentication.
440
455
/// If an exercise's id is not found in the checksum map, it is considered new.
@@ -550,11 +565,9 @@ impl TmcClient {
550
565
/// If authentication is required but the client is not authenticated, if there's some problem reaching the API, or if the API returns an error.
551
566
pub fn check_submission (
552
567
& self ,
553
- submission_url : & str ,
568
+ submission_id : u32 ,
554
569
) -> Result < SubmissionProcessingStatus , ClientError > {
555
- let url = Url :: parse ( submission_url)
556
- . map_err ( |e| ClientError :: UrlParse ( submission_url. to_string ( ) , e) ) ?;
557
- api_v8:: get_submission_processing_status ( self , url)
570
+ api_v8:: get_submission ( self , submission_id)
558
571
}
559
572
560
573
/// Request code review. Requires authentication.
0 commit comments