Search in sources :

Example 1 with ProjectExportTaskHandle

use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle in project webanno by webanno.

the class ProjectExportServiceImpl method startProjectExportCuratedDocumentsTask.

@Override
public ProjectExportTaskHandle startProjectExportCuratedDocumentsTask(ProjectExportRequest aRequest, String aUsername) {
    ProjectExportTaskHandle handle = new ProjectExportTaskHandle();
    ProjectExportTaskMonitor monitor = new ProjectExportTaskMonitor();
    ProjectExportCuratedDocumentsTask task = new ProjectExportCuratedDocumentsTask(handle, monitor, aRequest, aUsername);
    return startTask(task);
}
Also used : ProjectExportTaskMonitor(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor) ProjectExportTaskHandle(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle)

Example 2 with ProjectExportTaskHandle

use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle in project webanno by webanno.

the class ProjectExportServiceImpl method startTask.

private ProjectExportTaskHandle startTask(ProjectExportTask_ImplBase aTask) {
    ProjectExportTaskHandle handle = aTask.getHandle();
    // This autowires the task fields manually.
    AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
    factory.autowireBean(aTask);
    factory.initializeBean(aTask, "transientTask");
    tasks.put(handle, new TaskInfo(taskExecutorService.submit(aTask), aTask));
    return handle;
}
Also used : ProjectExportTaskHandle(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory)

Example 3 with ProjectExportTaskHandle

use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle in project webanno by webanno.

the class ProjectExportServiceImpl method startProjectExportTask.

@Override
public ProjectExportTaskHandle startProjectExportTask(ProjectExportRequest aRequest, String aUsername) {
    ProjectExportTaskHandle handle = new ProjectExportTaskHandle();
    ProjectExportTaskMonitor monitor = new ProjectExportTaskMonitor();
    ProjectExportFullProjectTask task = new ProjectExportFullProjectTask(handle, monitor, aRequest, aUsername);
    return startTask(task);
}
Also used : ProjectExportTaskMonitor(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor) ProjectExportTaskHandle(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle)

Example 4 with ProjectExportTaskHandle

use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle 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

ProjectExportTaskHandle (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskHandle)4 ProjectExportTaskMonitor (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor)3 File (java.io.File)1 IOException (java.io.IOException)1 ZipFile (java.util.zip.ZipFile)1 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)1