Refactored the transcoder so that it only checks the ingest directory once before archiving, ingesting and cleaning up to avoid race conditions where it may transcode/remove a file without being archived
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
763c27ca95
commit
5e8da26257
@ -40,10 +40,7 @@ public class Repository {
|
||||
}
|
||||
|
||||
// archives files in the ingest directory
|
||||
public void archiveIngest() {
|
||||
File repo = new File(this.archivePath);
|
||||
File[] sourceFiles = repo.listFiles();
|
||||
|
||||
public void archiveIngest(File[] sourceFiles) {
|
||||
for (File f : sourceFiles) {
|
||||
Path filePath = Path.of(f.toString());
|
||||
String filename = filePath.getFileName().toString();
|
||||
@ -58,10 +55,7 @@ public class Repository {
|
||||
}
|
||||
|
||||
// clean up the ingest directory once we're done
|
||||
public void cleanupIngest() {
|
||||
File repo = new File(this.ingestPath);
|
||||
File[] sourceFiles = repo.listFiles();
|
||||
|
||||
public void cleanupIngest(File[] sourceFiles) {
|
||||
for (File f : sourceFiles) {
|
||||
f.delete();
|
||||
}
|
||||
|
@ -32,19 +32,19 @@ public class Transcoder {
|
||||
|
||||
// create a periodic timer task and start it
|
||||
public void run() {
|
||||
// save source video files
|
||||
this.repo.archiveIngest();
|
||||
// transcode video files to new format
|
||||
this.transcode();
|
||||
// cleanup old video files in ingest
|
||||
this.repo.cleanupIngest();
|
||||
// pull list of files to transcode
|
||||
File[] sourceFiles = this.repo.searchIngest();
|
||||
|
||||
// archive files
|
||||
this.repo.archiveIngest(sourceFiles);
|
||||
// transcode files
|
||||
this.transcode(sourceFiles);
|
||||
// cleanup old files
|
||||
this.repo.cleanupIngest(sourceFiles);
|
||||
}
|
||||
|
||||
// transcode files in the working directory
|
||||
public void transcode() {
|
||||
// search for files
|
||||
File[] sourceFiles = this.repo.searchIngest();
|
||||
|
||||
public void transcode(File[] sourceFiles) {
|
||||
// check if the ingest directory is empty
|
||||
if (sourceFiles.length == 0) {
|
||||
Logger.logger.info("There is nothing to transcode in ingest.");
|
||||
|
Loading…
Reference in New Issue
Block a user