Skip to content

Commit 7b9cf6d

Browse files
committed
wait for submission
1 parent 52a76f2 commit 7b9cf6d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tmc-langs-cli/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,14 @@ fn run() -> Result<()> {
749749
.context("Failed to submit")?;
750750

751751
print_result_as_json(&new_submission)?;
752+
} else if let Some(matches) = matches.subcommand_matches("wait-for-submission") {
753+
let submission_url = matches.value_of("submission-url").unwrap();
754+
let submission_finished = core
755+
.wait_for_submission(submission_url)
756+
.context("Failed while waiting for submissions")?;
757+
let submission_finished = serde_json::to_string(&submission_finished)
758+
.context("Failed to serialize submission results")?;
759+
println!("{}", submission_finished);
752760
} else if let Some(_matches) = matches.subcommand_matches("get-exercise-updates") {
753761
let course_id = matches.value_of("course-id").unwrap();
754762
let course_id = into_usize(course_id)?;

tmc-langs-core/src/tmc_core.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use std::collections::HashMap;
1616
use std::io::Write;
1717
use std::path::Path;
1818
use std::path::PathBuf;
19+
use std::thread;
20+
use std::time::Duration;
1921
use tempfile::NamedTempFile;
2022
use tmc_langs_util::task_executor;
2123

@@ -387,6 +389,18 @@ impl TmcCore {
387389
result
388390
}
389391

392+
pub fn wait_for_submission(&self, submission_url: &str) -> Result<SubmissionFinished> {
393+
loop {
394+
match self.check_submission(submission_url)? {
395+
SubmissionProcessingStatus::Finished(f) => return Ok(*f),
396+
SubmissionProcessingStatus::Processing(_p) => {
397+
// todo: report status
398+
thread::sleep(Duration::from_secs(1));
399+
}
400+
}
401+
}
402+
}
403+
390404
/// Fetches the course's exercises from the server,
391405
/// and finds new or updated exercises.
392406
/// If an exercise's id is not found in the checksum map, it is considered new.

0 commit comments

Comments
 (0)