Skip to content

Commit

Permalink
save failed results
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanMarmelab committed Oct 11, 2023
1 parent fbfa28b commit 90cc38f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 23 additions & 8 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ import initializeKubeClient from '../tasks/initializeKubeClient';
import retrieveGitInformations from '../tasks/retrieveGitInformations';
import retrieveGreenFrameProject from '../tasks/retrieveGreenFrameProject';
import runScenarioAndSaveResults from '../tasks/runScenariosAndSaveResult';

let analysisId: string | null = null;

process.on('SIGINT' || 'SIGKILL' || 'SIGTERM' || 'SIGQUIT', async function () {
if (analysisId !== null) {
try {
await saveFailedAnalysis(analysisId, {
errorCode: ERROR_CODES.UNKNOWN_ERROR,
errorMessage: 'Analysis stopped with Ctrl+C',
});
} catch (error) {
console.log('error :', error);
}
}

setTimeout(() => {
process.exit(1);
}, 299);
});

class AnalyzeCommand extends Command {
static args = [
{
Expand Down Expand Up @@ -121,13 +141,6 @@ class AnalyzeCommand extends Command {
};

async run() {
let analysisId;

process.on('SIGINT', async () => {
console.log("Vous avez appuyé sur Ctrl + C. L'événement a été déclenché.");
this.exit(0);
});

try {
const commandParams = await this.parse(AnalyzeCommand);
const configFilePath =
Expand Down Expand Up @@ -210,13 +223,15 @@ class AnalyzeCommand extends Command {
});
const tasks = task.newListr(tasksDefinition, {
rendererOptions: { collapse: false },
registerSignalListeners: false,
});
return tasks;
},
},
],
{
renderer: process.env.DEBUG ? 'verbose' : 'default',
registerSignalListeners: false,
}
);
const { result } = await tasks.run();
Expand All @@ -231,7 +246,7 @@ class AnalyzeCommand extends Command {
}

try {
if (analysisId) {
if (analysisId !== null) {
await saveFailedAnalysis(analysisId, {
errorCode: error.errorCode || ERROR_CODES.UNKNOWN_ERROR,
errorMessage: error.response?.data || error.message,
Expand Down
2 changes: 1 addition & 1 deletion src/services/api/analyses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const saveFailedAnalysis = async (
{ errorCode, errorMessage }: { errorCode: string; errorMessage: string }
) => {
debug('saveFailedAnalysis', analysisId);
return instance.post(`/analyses/${analysisId}/fail`, {
return instance.post(`/analyses/${analysisId}/failed`, {
errorCode,
errorMessage: errorMessage.toString(),
});
Expand Down

0 comments on commit 90cc38f

Please sign in to comment.