Search in sources :

Example 6 with ProjectExportTaskMonitor

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);
                }
            }
        }
    }
}
Also used : ProjectExportTaskMonitor(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor) ProjectExportTaskHandle(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

ProjectExportTaskMonitor (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor)6 ZipFile (java.util.zip.ZipFile)4 ProjectExportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportRequest)3 ProjectExportTaskHandle (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle)3 File (java.io.File)3 IOException (java.io.IOException)3 ProjectImportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest)2 ExportedProject (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)1 ImportExportService (de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService)1 ANNOTATION_FOLDER (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.ANNOTATION_FOLDER)1 DOCUMENT_FOLDER (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.DOCUMENT_FOLDER)1 PROJECT_FOLDER (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.PROJECT_FOLDER)1 RepositoryProperties (de.tudarmstadt.ukp.clarin.webanno.api.RepositoryProperties)1 CORRECTION_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER)1 INITIAL_CAS_PSEUDO_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER)1 PROJECT_TYPE_AUTOMATION (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_AUTOMATION)1