forked from j62/ctbrec
Run NextGenLocalRecorder.startRecordingProcess(Model) async
This commit is contained in:
parent
52cdc82044
commit
ebaf4c4c9f
|
@ -22,6 +22,7 @@ import java.util.Optional;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -214,23 +215,26 @@ public class NextGenLocalRecorder implements Recorder {
|
|||
}
|
||||
}
|
||||
|
||||
private void startRecordingProcess(Model model) throws IOException {
|
||||
recorderLock.lock();
|
||||
try {
|
||||
preconditions.check(model);
|
||||
LOG.info("Starting recording for model {}", model.getName());
|
||||
Download download = createDownload(model);
|
||||
Recording rec = createRecording(download);
|
||||
completionService.submit(createDownloadJob(rec));
|
||||
} catch (RecordUntilExpiredException e) {
|
||||
LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage());
|
||||
executeRecordUntilSubsequentAction(model);
|
||||
} catch (PreconditionNotMetException e) {
|
||||
LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage());
|
||||
return;
|
||||
} finally {
|
||||
recorderLock.unlock();
|
||||
}
|
||||
private CompletableFuture<Void> startRecordingProcess(Model model) throws IOException {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
recorderLock.lock();
|
||||
try {
|
||||
preconditions.check(model);
|
||||
LOG.info("Starting recording for model {}", model.getName());
|
||||
Download download = createDownload(model);
|
||||
Recording rec = createRecording(download);
|
||||
completionService.submit(createDownloadJob(rec));
|
||||
} catch (RecordUntilExpiredException e) {
|
||||
LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage());
|
||||
executeRecordUntilSubsequentAction(model);
|
||||
} catch (PreconditionNotMetException e) {
|
||||
LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage());
|
||||
} catch (IOException e) {
|
||||
LOG.error("Couldn't start recording process for {}", model, e);
|
||||
} finally {
|
||||
recorderLock.unlock();
|
||||
}
|
||||
}, downloadPool);
|
||||
}
|
||||
|
||||
private Download createDownload(Model model) {
|
||||
|
@ -262,14 +266,14 @@ public class NextGenLocalRecorder implements Recorder {
|
|||
};
|
||||
}
|
||||
|
||||
private void executeRecordUntilSubsequentAction(Model model) throws IOException {
|
||||
private void executeRecordUntilSubsequentAction(Model model) {
|
||||
if (model.getRecordUntilSubsequentAction() == PAUSE) {
|
||||
model.setSuspended(true);
|
||||
} else if (model.getRecordUntilSubsequentAction() == REMOVE) {
|
||||
try {
|
||||
LOG.info("Removing {} because the recording timeframe ended at {}", model, model.getRecordUntil().atZone(ZoneId.systemDefault()));
|
||||
stopRecording(model);
|
||||
} catch (InvalidKeyException | NoSuchAlgorithmException e1) {
|
||||
} catch (Exception e1) {
|
||||
LOG.error("Error while stopping recording", e1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue