Search in sources :

Example 1 with SingularityExecutorTaskCleanup

use of com.hubspot.singularity.executor.task.SingularityExecutorTaskCleanup in project Singularity by HubSpot.

the class SingularityExecutorCleanup method cleanTask.

private TaskCleanupResult cleanTask(SingularityExecutorTaskDefinition taskDefinition, Optional<SingularityTaskHistory> taskHistory) {
    SingularityExecutorTaskLogManager logManager = new SingularityExecutorTaskLogManager(taskDefinition, templateManager, baseConfiguration, executorConfiguration, LOG, jsonObjectFileHelper);
    SingularityExecutorTaskCleanup taskCleanup = new SingularityExecutorTaskCleanup(logManager, executorConfiguration, taskDefinition, LOG, dockerUtils);
    boolean cleanupTaskAppDirectory = !taskDefinition.getExecutorData().getPreserveTaskSandboxAfterFinish().or(Boolean.FALSE);
    if (taskHistory.isPresent()) {
        final Optional<SingularityTaskHistoryUpdate> lastUpdate = JavaUtils.getLast(taskHistory.get().getTaskUpdates());
        if (lastUpdate.isPresent() && lastUpdate.get().getTaskState().isFailed()) {
            final long delta = System.currentTimeMillis() - lastUpdate.get().getTimestamp();
            if (delta < cleanupConfiguration.getCleanupAppDirectoryOfFailedTasksAfterMillis()) {
                LOG.info("Not cleaning up task app directory of {} because only {} has elapsed since it failed (will cleanup after {})", taskDefinition.getTaskId(), JavaUtils.durationFromMillis(delta), JavaUtils.durationFromMillis(cleanupConfiguration.getCleanupAppDirectoryOfFailedTasksAfterMillis()));
                cleanupTaskAppDirectory = false;
            }
        }
    }
    if (taskDefinition.shouldLogrotateLogFile()) {
        checkForUncompressedLogrotatedFile(taskDefinition);
    }
    boolean isDocker = (taskHistory.isPresent() && taskHistory.get().getTask().getTaskRequest().getDeploy().getContainerInfo().isPresent() && taskHistory.get().getTask().getTaskRequest().getDeploy().getContainerInfo().get().getType() == SingularityContainerType.DOCKER);
    return taskCleanup.cleanup(cleanupTaskAppDirectory, isDocker);
}
Also used : SingularityExecutorTaskLogManager(com.hubspot.singularity.executor.task.SingularityExecutorTaskLogManager) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityExecutorTaskCleanup(com.hubspot.singularity.executor.task.SingularityExecutorTaskCleanup)

Aggregations

SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)1 SingularityExecutorTaskCleanup (com.hubspot.singularity.executor.task.SingularityExecutorTaskCleanup)1 SingularityExecutorTaskLogManager (com.hubspot.singularity.executor.task.SingularityExecutorTaskLogManager)1