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);
}
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;
}
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);
}
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);
}
}
}
}
}
Aggregations