Skip to content

Commit

Permalink
Add option to reprocess files on modify to CsvFolderReader (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdbaker authored and jbaker-dstl committed Feb 18, 2019
1 parent a622254 commit 38a2638
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import static java.nio.file.StandardWatchEventKinds.OVERFLOW;

import java.io.File;
Expand Down Expand Up @@ -60,6 +61,16 @@ public class CsvFolderReader extends BaleenCollectionReader {
)
private String[] folders;

/**
* Should files be reprocessed when modified?
*
* @baleen.config false
*/
public static final String PARAM_REPROCESS_ON_MODIFY = "reprocess";

@ConfigurationParameter(name = PARAM_REPROCESS_ON_MODIFY, defaultValue = "false")
private boolean reprocessOnModify = false;

/**
* Should folders be processed recursively (i.e. should we watch subfolders too)?
*
Expand Down Expand Up @@ -163,7 +174,13 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attr)
}

private void registerDirectory(Path path) throws IOException {
WatchKey key = path.register(watcher, ENTRY_CREATE, ENTRY_DELETE);
WatchKey key;
if (reprocessOnModify) {
key = path.register(watcher, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE);
} else {
key = path.register(watcher, ENTRY_CREATE, ENTRY_DELETE);
}

watchKeys.put(key, path);

getMonitor().counter("directories").inc();
Expand Down

0 comments on commit 38a2638

Please sign in to comment.