use of com.enonic.xp.vacuum.VacuumResult in project xp by enonic.
the class VacuumServiceImpl method doVacuum.
private VacuumResult doVacuum(final VacuumParameters params) {
// Retrieves the tasks to execute
VacuumTasks tasks = getTasks(params);
LOG.info("Starting vacuum. Running " + tasks.size() + " tasks...");
if (params.getVacuumListener() != null) {
params.getVacuumListener().vacuumBegin(tasks.size());
}
final VacuumResult.Builder taskResults = VacuumResult.create();
for (final VacuumTask task : tasks) {
LOG.info("Running vacuum task [" + task.name() + "]...");
final VacuumTaskParams taskParams = VacuumTaskParams.create().listener(params.getVacuumListener()).ageThreshold(getAgeThresholdMs(params)).versionsBatchSize(config.versionsBatchSize()).build();
final VacuumTaskResult taskResult = task.execute(taskParams);
LOG.info(task.name() + " : " + taskResult.toString());
taskResults.add(taskResult);
LOG.info("Vacuum task [" + task.name() + "] done");
}
LOG.info("Vacuum done");
return taskResults.build();
}
use of com.enonic.xp.vacuum.VacuumResult in project xp by enonic.
the class VacuumServiceImplTest method runTasks.
@Test
public void runTasks() throws Exception {
final VacuumServiceImpl service = new VacuumServiceImpl();
service.activate(mock(VacuumConfig.class, i -> i.getMethod().getDefaultValue()));
service.addTask(new VacuumTask() {
@Override
public VacuumTaskResult execute(final VacuumTaskParams params) {
return VacuumTaskResult.create().processed().build();
}
@Override
public int order() {
return 10;
}
@Override
public String name() {
return "ATask";
}
});
service.addTask(new VacuumTask() {
@Override
public VacuumTaskResult execute(final VacuumTaskParams params) {
return VacuumTaskResult.create().failed().build();
}
@Override
public int order() {
return 0;
}
@Override
public String name() {
return "AnotherTask";
}
});
final VacuumResult result = NodeHelper.runAsAdmin(() -> service.vacuum(VacuumParameters.create().build()));
assertEquals(2, result.getResults().size());
}
use of com.enonic.xp.vacuum.VacuumResult in project xp by enonic.
the class VacuumTaskHandler method execute.
public void execute() {
final ProgressReporter progressReporter = TaskProgressReporterContext.current();
final VacuumResult result = vacuumService.vacuum(VacuumParameters.create().ageThreshold(ageThreshold != null ? Duration.parse(ageThreshold) : null).taskNames(tasks == null || tasks.isEmpty() ? DEFAULT_VACUUM_TASKS : tasks).vacuumListener(new VacuumListenerImpl(progressReporter)).build());
try {
progressReporter.info(MAPPER.writeValueAsString(MAPPER.createObjectNode().putPOJO("taskResults", result.getResults())));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
Aggregations