Search in sources :

Example 1 with VacuumResult

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();
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumResult(com.enonic.xp.vacuum.VacuumResult)

Example 2 with VacuumResult

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());
}
Also used : Test(org.junit.jupiter.api.Test) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumResult(com.enonic.xp.vacuum.VacuumResult) VacuumParameters(com.enonic.xp.vacuum.VacuumParameters) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) Mockito.mock(org.mockito.Mockito.mock) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumResult(com.enonic.xp.vacuum.VacuumResult) Test(org.junit.jupiter.api.Test)

Example 3 with VacuumResult

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);
    }
}
Also used : VacuumResult(com.enonic.xp.vacuum.VacuumResult) ProgressReporter(com.enonic.xp.task.ProgressReporter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) VacuumListenerImpl(com.enonic.xp.app.system.listener.VacuumListenerImpl)

Aggregations

VacuumResult (com.enonic.xp.vacuum.VacuumResult)3 VacuumTaskResult (com.enonic.xp.vacuum.VacuumTaskResult)2 VacuumListenerImpl (com.enonic.xp.app.system.listener.VacuumListenerImpl)1 NodeHelper (com.enonic.xp.repo.impl.node.NodeHelper)1 ProgressReporter (com.enonic.xp.task.ProgressReporter)1 VacuumParameters (com.enonic.xp.vacuum.VacuumParameters)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Test (org.junit.jupiter.api.Test)1 Mockito.mock (org.mockito.Mockito.mock)1