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
|
// archives files in the ingest directory
|
||||||
public void archiveIngest() {
|
public void archiveIngest(File[] sourceFiles) {
|
||||||
File repo = new File(this.archivePath);
|
|
||||||
File[] sourceFiles = repo.listFiles();
|
|
||||||
|
|
||||||
for (File f : sourceFiles) {
|
for (File f : sourceFiles) {
|
||||||
Path filePath = Path.of(f.toString());
|
Path filePath = Path.of(f.toString());
|
||||||
String filename = filePath.getFileName().toString();
|
String filename = filePath.getFileName().toString();
|
||||||
@ -58,10 +55,7 @@ public class Repository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clean up the ingest directory once we're done
|
// clean up the ingest directory once we're done
|
||||||
public void cleanupIngest() {
|
public void cleanupIngest(File[] sourceFiles) {
|
||||||
File repo = new File(this.ingestPath);
|
|
||||||
File[] sourceFiles = repo.listFiles();
|
|
||||||
|
|
||||||
for (File f : sourceFiles) {
|
for (File f : sourceFiles) {
|
||||||
f.delete();
|
f.delete();
|
||||||
}
|
}
|
||||||
|
@ -32,19 +32,19 @@ public class Transcoder {
|
|||||||
|
|
||||||
// create a periodic timer task and start it
|
// create a periodic timer task and start it
|
||||||
public void run() {
|
public void run() {
|
||||||
// save source video files
|
// pull list of files to transcode
|
||||||
this.repo.archiveIngest();
|
File[] sourceFiles = this.repo.searchIngest();
|
||||||
// transcode video files to new format
|
|
||||||
this.transcode();
|
// archive files
|
||||||
// cleanup old video files in ingest
|
this.repo.archiveIngest(sourceFiles);
|
||||||
this.repo.cleanupIngest();
|
// transcode files
|
||||||
|
this.transcode(sourceFiles);
|
||||||
|
// cleanup old files
|
||||||
|
this.repo.cleanupIngest(sourceFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
// transcode files in the working directory
|
// transcode files in the working directory
|
||||||
public void transcode() {
|
public void transcode(File[] sourceFiles) {
|
||||||
// search for files
|
|
||||||
File[] sourceFiles = this.repo.searchIngest();
|
|
||||||
|
|
||||||
// check if the ingest directory is empty
|
// check if the ingest directory is empty
|
||||||
if (sourceFiles.length == 0) {
|
if (sourceFiles.length == 0) {
|
||||||
Logger.logger.info("There is nothing to transcode in ingest.");
|
Logger.logger.info("There is nothing to transcode in ingest.");
|
||||||
|
Loading…
Reference in New Issue
Block a user