UI Update

This commit is contained in:
2025-11-27 18:02:00 +03:00
parent eef82577ab
commit 8f05f40bb2
7 changed files with 65 additions and 72 deletions

View File

@@ -26,7 +26,12 @@ function cleanOutput(input: string) {
);
}
function runCommand(command: string, cwd: string, onData: (chunk: string) => void) {
function runCommand(
command: string,
cwd: string,
onData: (chunk: string) => void,
timeoutMs?: number
) {
return new Promise<void>((resolve, reject) => {
const child = spawn(command, {
cwd,
@@ -34,23 +39,37 @@ function runCommand(command: string, cwd: string, onData: (chunk: string) => voi
env: { ...process.env, CI: process.env.CI || "1" }
});
let timeout: NodeJS.Timeout | null = null;
let timedOut = false;
const emitLines = (chunk: Buffer) => {
const cleaned = cleanOutput(chunk.toString()).replace(/\r\n|\r/g, "\n");
cleaned.split("\n").forEach((line) => {
onData(line);
if (line.trim().length > 0) onData(line);
});
};
if (timeoutMs) {
timeout = setTimeout(() => {
timedOut = true;
onData(`Test zaman aşımına uğradı (${timeoutMs / 1000}s)`);
child.kill("SIGKILL");
}, timeoutMs);
}
child.stdout.on("data", emitLines);
child.stderr.on("data", emitLines);
child.on("error", (err) => {
if (timeout) clearTimeout(timeout);
onData(`Hata: ${err.message}`);
reject(err);
});
child.on("close", (code) => {
if (code === 0) {
if (timeout) clearTimeout(timeout);
if (timedOut) {
reject(new Error("Test zaman aşımına uğradı"));
} else if (code === 0) {
resolve();
} else {
reject(new Error(`Komut kod ${code} ile kapandı`));
@@ -141,13 +160,13 @@ class JobService {
await Job.findByIdAndUpdate(jobId, { status: "running", lastMessage: "Çalıştırılıyor..." });
await this.emitStatus(jobId, { status: "running", lastMessage: "Çalıştırılıyor..." } as JobDocument);
try {
const repoDir = await cloneOrPull(job, (line) => pushLog(line));
await ensureDependencies(repoDir, (line) => pushLog(line));
pushLog(`Test komutu çalıştırılıyor: ${job.testCommand}`);
await runCommand(job.testCommand, repoDir, (line) => pushLog(line));
pushLog("Test tamamlandı: Başarılı");
const duration = Date.now() - startedAt;
try {
const repoDir = await cloneOrPull(job, (line) => pushLog(line));
await ensureDependencies(repoDir, (line) => pushLog(line));
pushLog(`Test komutu çalıştırılıyor: ${job.testCommand}`);
await runCommand(job.testCommand, repoDir, (line) => pushLog(line), 180_000);
pushLog("Test tamamlandı: Başarılı");
const duration = Date.now() - startedAt;
await Job.findByIdAndUpdate(jobId, {
status: "success",
lastRunAt: new Date(),