Skip to content

Commit

Permalink
fix(#151): settime
Browse files Browse the repository at this point in the history
  • Loading branch information
mjh000526 committed Dec 3, 2024
1 parent 2d32b56 commit b5bd6b8
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions apps/backend/src/docker/docker.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,35 @@ export class DockerConsumer {
}
const stream = await this.dockerExcution(inputs, mainFileName, container);
let output = '';
const timeout = setTimeout(async () => {
stream.destroy(new Error('Timeout'));
}, 10000);
//desciption: 스트림 종료 후 결과 반환
return new Promise((resolve, reject) => {
//desciption: 스트림에서 데이터 수집
let time = null;

const onStreamClose = async () => {
try {
let result = await this.filterAnsiCode(output);
clearTimeout(time);
if (inputs.length !== 0) {
result = result.split('\n').slice(1).join('\n');
}
resolve(result);
} catch (err) {
reject(err);
}
};

// Timeout 설정
time = setTimeout(() => {
stream.destroy(new Error('Timeout'));
}, 10000);

// 스트림에서 데이터 수집
stream.on('data', (chunk) => {
output += chunk.toString();
});
stream.on('close', async () => {
let result = await this.filterAnsiCode(output);
clearTimeout(timeout);
if (inputs.length !== 0) {
result = result.split('\n').slice(1).join('\n');
}
resolve(result);
});

// 스트림 종료 대기
stream.on('close', onStreamClose);
stream.on('end', onStreamClose);
stream.on('error', reject);
});
}
Expand Down

0 comments on commit b5bd6b8

Please sign in to comment.