Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/catch ctrc+c #65

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import logErrorOnSentry from '../services/errors/Sentry';
import { DEFAULT_SAMPLES } from '../constants';
export const DEFAULT_CONFIG_FILE = './.greenframe.yml';

import checkGreenFrameSecretToken from '../tasks/checkGreenFrameSecretToken';
import createNewAnalysis from '../tasks/createNewAnalysis';
import detectDockerVersion from '../tasks/detectDockerVersion';
import detectKubernetesVersion from '../tasks/detectKubernetesVersion';
Expand All @@ -20,7 +21,26 @@ import initializeKubeClient from '../tasks/initializeKubeClient';
import retrieveGitInformations from '../tasks/retrieveGitInformations';
import retrieveGreenFrameProject from '../tasks/retrieveGreenFrameProject';
import runScenarioAndSaveResults from '../tasks/runScenariosAndSaveResult';
import checkGreenFrameSecretToken from '../tasks/checkGreenFrameSecretToken';

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,7 +141,6 @@ class AnalyzeCommand extends Command {
};

async run() {
let analysisId;
try {
const commandParams = await this.parse(AnalyzeCommand);
const configFilePath =
Expand Down Expand Up @@ -204,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 @@ -225,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
Loading