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

ExerciseDockerCompose => Refactor code

parent e8114e05
Branches
Tags
No related merge requests found
...@@ -44,6 +44,10 @@ class ExerciseDockerCompose { ...@@ -44,6 +44,10 @@ class ExerciseDockerCompose {
this.events.emit('logs', message, error, displayable, this.currentStep); 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) { private registerChildProcess(childProcess: ChildProcessWithoutNullStreams, resolve: (value: (number | PromiseLike<number>)) => void, reject: (reason?: unknown) => void, displayable: boolean) {
childProcess.stdout.on('data', (data) => { childProcess.stdout.on('data', (data) => {
this.log(data.toString(), false, displayable); this.log(data.toString(), false, displayable);
...@@ -86,7 +90,7 @@ class ExerciseDockerCompose { ...@@ -86,7 +90,7 @@ class ExerciseDockerCompose {
}); });
} catch ( error ) { } catch ( error ) {
this.endStep(`Error while running the docker compose file`, true); 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; return;
} }
this.endStep(`Docker Compose file run successfully`, false); this.endStep(`Docker Compose file run successfully`, false);
...@@ -110,7 +114,7 @@ class ExerciseDockerCompose { ...@@ -110,7 +114,7 @@ class ExerciseDockerCompose {
}); });
} catch ( error ) { } catch ( error ) {
this.endStep(`Error while getting the linked services logs`, true); 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; return;
} }
this.endStep(`Linked services logs acquired`, false); this.endStep(`Linked services logs acquired`, false);
...@@ -135,10 +139,10 @@ class ExerciseDockerCompose { ...@@ -135,10 +139,10 @@ class ExerciseDockerCompose {
}); });
} catch ( error ) { } catch ( error ) {
this.endStep(`Error stop and remove containers`, true); 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; 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 { ...@@ -161,14 +165,14 @@ class ExerciseDockerCompose {
}); });
} catch ( error ) { } catch ( error ) {
this.endStep(`Error while removing dangling images`, true); 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; 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