use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor in project webanno by webanno.
the class ProjectExportServiceImpl method cleanUp.
private void cleanUp() {
for (Entry<ProjectExportTaskHandle, TaskInfo> e : tasks.entrySet()) {
ProjectExportTaskMonitor monitor = e.getValue().task.getMonitor();
// Do not clean up running tasks or tasks that have not started yet
if (asList(NOT_STARTED, RUNNING).contains(monitor.getState())) {
continue;
}
// Remove task info from the tasks map one hour after completion/failure/etc.
long age = System.currentTimeMillis() - monitor.getEndTime();
if (age > Duration.ofHours(1).toMillis()) {
log.info("Cleaning up stale export task for project [{}]:", e.getValue().task.getRequest().getProject().getName());
tasks.remove(e.getKey());
File exportedFile = e.getValue().task.getMonitor().getExportedFile();
if (exportedFile.exists()) {
try {
FileUtils.forceDelete(exportedFile);
} catch (IOException ex) {
log.error("Unable to clean up stale exported file [{}]:", exportedFile, ex);
}
}
}
}
}
Aggregations