Skip to content
Snippets Groups Projects
Commit 04e9ad7c authored by michael.minelli's avatar michael.minelli
Browse files

ExerciseDockerCompose => Refactor code

parent e8114e05
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,10 @@ class ExerciseDockerCompose {
this.events.emit('logs', message, error, displayable, this.currentStep);
}
private finished(success: boolean, code: number) {
this.events.emit('finished', success, code);
}
private registerChildProcess(childProcess: ChildProcessWithoutNullStreams, resolve: (value: (number | PromiseLike<number>)) => void, reject: (reason?: unknown) => void, displayable: boolean) {
childProcess.stdout.on('data', (data) => {
this.log(data.toString(), false, displayable);
......@@ -86,7 +90,7 @@ class ExerciseDockerCompose {
});
} catch ( error ) {
this.endStep(`Error while running the docker compose file`, true);
this.events.emit('finished', false, ExerciseCheckerError.DOCKER_COMPOSE_RUN_ERROR);
this.finished(false, ExerciseCheckerError.DOCKER_COMPOSE_RUN_ERROR);
return;
}
this.endStep(`Docker Compose file run successfully`, false);
......@@ -110,7 +114,7 @@ class ExerciseDockerCompose {
});
} catch ( error ) {
this.endStep(`Error while getting the linked services logs`, true);
this.events.emit('finished', false, ExerciseCheckerError.DOCKER_COMPOSE_LOGS_ERROR);
this.finished(false, ExerciseCheckerError.DOCKER_COMPOSE_LOGS_ERROR);
return;
}
this.endStep(`Linked services logs acquired`, false);
......@@ -135,10 +139,10 @@ class ExerciseDockerCompose {
});
} catch ( error ) {
this.endStep(`Error stop and remove containers`, true);
this.events.emit('finished', false, ExerciseCheckerError.DOCKER_COMPOSE_DOWN_ERROR);
this.finished(false, ExerciseCheckerError.DOCKER_COMPOSE_DOWN_ERROR);
return;
}
this.events.emit('endStep', this.currentStep, `Containers stopped and removed`, false);
this.endStep(`Containers stopped and removed`, false);
}
}
......@@ -161,14 +165,14 @@ class ExerciseDockerCompose {
});
} catch ( error ) {
this.endStep(`Error while removing dangling images`, true);
this.events.emit('finished', false, ExerciseCheckerError.DOCKER_COMPOSE_REMOVE_DANGLING_ERROR);
this.finished(false, ExerciseCheckerError.DOCKER_COMPOSE_REMOVE_DANGLING_ERROR);
return;
}
this.events.emit('endStep', this.currentStep, `Dangling images removed`, false);
this.endStep(`Dangling images removed`, false);
}
}
this.events.emit('finished', true, containerExitCode);
this.finished(true, containerExitCode);
})();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment