WIP: Submit transcoding jobs via a HTTP API #6

Draft
ansv7779 wants to merge 22 commits from api-submission into master
3 changed files with 32 additions and 12 deletions
Showing only changes of commit 39a46c0b0c - Show all commits

View File

@ -149,15 +149,20 @@ public class ApiController {
UUID uuid = UUID.fromString(id);
Transcription transcription = transcriptionService.getTranscription(owner, uuid)
.orElseThrow(() -> new TranscriptionNotFound(id));
transcriptionService.submitTranscriptionJob(transcription, jobId -> uriComponentsBuilder.cloneBuilder()
.path("api")
.pathSegment("transcriptions")
.pathSegment("job")
.pathSegment("callback")
.pathSegment(jobId.toString())
.build()
.toUri());
return ResponseEntity.accepted().build();
try {
transcriptionService.submitTranscriptionJob(transcription, jobId -> uriComponentsBuilder.cloneBuilder()
.path("api")
.pathSegment("transcriptions")
.pathSegment("job")
.pathSegment("callback")
.pathSegment(jobId.toString())
.build()
.toUri());
return ResponseEntity.accepted().build();
} catch (IOException e) {
LOG.log(System.Logger.Level.ERROR, "Failed to submit job", e);
throw new JobSubmissionFailed(e);
}
}
@PostMapping("/api/transcriptions/job/callback/{jobId}")

View File

@ -0,0 +1,14 @@
package se.su.dsv.whisperapi.api;
import org.springframework.http.HttpStatus;
import org.springframework.web.ErrorResponseException;
import java.net.URI;
public class JobSubmissionFailed extends ErrorResponseException {
public JobSubmissionFailed(Throwable cause) {
super(HttpStatus.INTERNAL_SERVER_ERROR, cause);
setType(URI.create("https://gitea.dsv.su.se/DMC/whisper-frontend/wiki/Errors#job-submission-failed"));
setTitle("Job submission failed");
}
}

View File

@ -69,7 +69,10 @@ public class TranscriptionService {
}
}
public void submitTranscriptionJob(Transcription transcription, CallbackUriGenerator callbackUriGenerator) {
public void submitTranscriptionJob(Transcription transcription, CallbackUriGenerator callbackUriGenerator)
throws IOException
{
Files.createDirectories(jobsDirectory);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
List<SourceFile> files = transcriptionRepository.getFiles(transcription);
@ -96,8 +99,6 @@ public class TranscriptionService {
objectMapper.writeValue(out, whisperJob);
Job job = new Job(jobId, new Job.Status.Pending(), file);
transcriptionRepository.createNewJob(transcription, job);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}