Added comments to explain stuff.

This commit is contained in:
Andrew Lalis 2023-01-25 12:54:28 +01:00
parent aff5ffedf9
commit f23002a6b8
3 changed files with 25 additions and 1 deletions

View File

@ -32,3 +32,4 @@ build/
.vscode/ .vscode/
.sample_data .sample_data
exercise_submission_temp_files/

View File

@ -10,11 +10,22 @@ import java.time.LocalDateTime;
@Entity @Entity
@Table(name = "exercise_submission") @Table(name = "exercise_submission")
public class ExerciseSubmission { public class ExerciseSubmission {
/**
* The status of a submission.
* <ul>
* <li>Each submission starts as WAITING.</li>
* <li>The status changes to PROCESSING once it's picked up for processing.</li>
* <li>If processing fails, the status changes to FAILED.</li>
* <li>If processing is successful, the status changes to COMPLETED.</li>
* <li>Once a completed submission is verified either automatically or manually, it's set to VERIFIED.</li>
* </ul>
*/
public enum Status { public enum Status {
WAITING, WAITING,
PROCESSING, PROCESSING,
FAILED, FAILED,
COMPLETED COMPLETED,
VERIFIED
} }
@Id @Id

View File

@ -211,6 +211,17 @@ public class ExerciseSubmissionService {
log.info("Processing of submission {} complete.", submission.getId()); log.info("Processing of submission {} complete.", submission.getId());
} }
/**
* Uses the `ffmpeg` system command to process a raw input video and produce
* a compressed, reduced-size output video that's ready for usage in the
* application.
* @param dir The working directory.
* @param inFile The input file to read from.
* @param outFile The output file to write to. MUST have a ".mp4" extension.
* @throws IOException If a filesystem error occurs.
* @throws CommandFailedException If the ffmpeg command fails.
* @throws InterruptedException If the ffmpeg command is interrupted.
*/
private void processVideo(Path dir, Path inFile, Path outFile) throws IOException, InterruptedException { private void processVideo(Path dir, Path inFile, Path outFile) throws IOException, InterruptedException {
Path tmpStdout = Files.createTempFile(dir, "stdout-", ".log"); Path tmpStdout = Files.createTempFile(dir, "stdout-", ".log");
Path tmpStderr = Files.createTempFile(dir, "stderr-", ".log"); Path tmpStderr = Files.createTempFile(dir, "stderr-", ".log");
@ -240,6 +251,7 @@ public class ExerciseSubmissionService {
String reductionFactorStr = String.format("%.3f%%", reductionFactor * 100); String reductionFactorStr = String.format("%.3f%%", reductionFactor * 100);
log.info("Processed video from {} bytes to {} bytes in {} seconds, {} reduction.", startSize, endSize, dur.getSeconds(), reductionFactorStr); log.info("Processed video from {} bytes to {} bytes in {} seconds, {} reduction.", startSize, endSize, dur.getSeconds(), reductionFactorStr);
// Delete the logs if everything was successful.
Files.deleteIfExists(tmpStdout); Files.deleteIfExists(tmpStdout);
Files.deleteIfExists(tmpStderr); Files.deleteIfExists(tmpStderr);
} }