Skip to content

Commit 9bad8a1

Browse files
authored
Merge pull request #215 from ukwa/use-latest-checkpoint
Extend API to simplify using the latest checkpoint
2 parents a81a648 + 0aa20a9 commit 9bad8a1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

engine/src/main/java/org/archive/crawler/framework/CheckpointService.java

+16
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,22 @@ public synchronized void setRecoveryCheckpointByName(String selectedCheckpoint)
393393
if(isRunning) {
394394
throw new RuntimeException("may not set recovery Checkpoint after launch");
395395
}
396+
// If the selectedCheckpoint is 'latest', pick up the latest checkpoint
397+
// and use that:
398+
if ("latest".equalsIgnoreCase(selectedCheckpoint)) {
399+
List<File> cps = this.findAvailableCheckpointDirectories();
400+
if (cps == null || cps.size() == 0) {
401+
LOGGER.warning(
402+
"Cannot find any checkpoints so cannot choose the latest one! Assuming we should launch a new crawl.");
403+
return;
404+
}
405+
// As per the API above, the most recent checkpoint is the first in
406+
// the list:
407+
File latestFile = cps.get(0);
408+
// For the checkpoint we use the folder name:
409+
selectedCheckpoint = latestFile.getName();
410+
}
411+
// Now setup the checkpoint:
396412
Checkpoint recoveryCheckpoint = new Checkpoint();
397413
recoveryCheckpoint.getCheckpointDir().setBase(getCheckpointsDir());
398414
recoveryCheckpoint.getCheckpointDir().setPath(selectedCheckpoint);

0 commit comments

Comments
 (0)