WIP: Submit transcoding jobs via a HTTP API #6
@ -149,6 +149,7 @@ public class ApiController {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
Transcription transcription = transcriptionService.getTranscription(owner, uuid)
|
||||
.orElseThrow(() -> new TranscriptionNotFound(id));
|
||||
try {
|
||||
transcriptionService.submitTranscriptionJob(transcription, jobId -> uriComponentsBuilder.cloneBuilder()
|
||||
.path("api")
|
||||
.pathSegment("transcriptions")
|
||||
@ -158,6 +159,10 @@ public class ApiController {
|
||||
.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}")
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user