Skip to content

Commit 09c0b80

Browse files
authored
Merge pull request #765 from GraphScope/fix/log-stream
fix: add stream log support
2 parents 3a3429d + ff3b386 commit 09c0b80

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

infra/sandbox/src/services/container-service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ class ContainerService {
586586
}
587587
);
588588

589+
stream.on("data", (chunk: Buffer) => {
590+
logger.info(`${chunk.toString()}`, {
591+
containerId: container.id,
592+
});
593+
});
594+
589595
stream.on("end", () => {
590596
resolve({ stdout, stderr });
591597
});

infra/sandbox/src/services/dependency-service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class NodePackageHandler implements DependencyHandler {
7272
}
7373
);
7474

75+
stream.on("data", (chunk: Buffer) => {
76+
logger.info(`${chunk.toString()}`, { position: 'NodePackageHandler', containerId: container.id });
77+
});
78+
7579
stream.on("end", async () => {
7680
try {
7781
const inspectData = await exec.inspect();
@@ -186,6 +190,10 @@ class PythonPackageHandler implements DependencyHandler {
186190
}
187191
);
188192

193+
stream.on("data", (chunk: Buffer) => {
194+
logger.info(`${chunk.toString()}`, { position: 'PythonPackageHandler', containerId: container.id });
195+
});
196+
189197
stream.on("end", async () => {
190198
try {
191199
const inspectData = await exec.inspect();

infra/sandbox/src/services/execution-service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ class ExecutionService {
384384
}
385385
);
386386

387+
stream.on("data", (chunk: Buffer) => {
388+
logger.info(`${chunk.toString()}`, {
389+
containerId: container.id,
390+
});
391+
});
392+
387393
stream.on("end", async () => {
388394
try {
389395
const inspectData = await exec.inspect();
@@ -418,6 +424,7 @@ class ExecutionService {
418424
});
419425
});
420426
}
427+
421428
}
422429

423430
export default new ExecutionService();

infra/sandbox/src/services/file-service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ApiError } from "../middleware/error-handler";
88
import { SandboxFiles } from "../types";
99
import gitService from "./git-service";
1010
import dockerConfig from "./docker-config";
11+
import tar from 'tar-stream'
1112

1213
// 固定工作目录,所有代码都存放在这里,由Git管理版本
1314
const WORK_DIR = "/home/sandbox";
@@ -363,7 +364,6 @@ class FileService {
363364
});
364365

365366
// Extract the zip file from the tar archive
366-
const tar = require("tar-stream");
367367
const extract = tar.extract();
368368

369369
// Use promise to properly handle async extraction
@@ -376,6 +376,7 @@ class FileService {
376376

377377
stream.on("data", (chunk: Buffer) => {
378378
chunks.push(chunk);
379+
logger.info(`${chunk.toString()}`, { position: 'FileService', containerId: container.id });
379380
});
380381

381382
stream.on("end", () => {
@@ -501,6 +502,10 @@ class FileService {
501502
}
502503
);
503504

505+
stream.on("data", (chunk: Buffer) => {
506+
logger.info(`${chunk.toString()}`, { position: 'FileService', containerId: container.id });
507+
});
508+
504509
stream.on("end", () => {
505510
resolve({ stdout, stderr });
506511
});
@@ -530,8 +535,7 @@ class FileService {
530535
// Read the file content
531536
const content = fs.readFileSync(localPath);
532537

533-
// Create a tar stream with the file
534-
const pack = require("tar-stream").pack();
538+
const pack = tar.pack();
535539

536540
// Add file to the tar stream
537541
const fileName = path.basename(containerPath);

infra/sandbox/src/services/git-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ Thumbs.db
597597
}
598598
);
599599

600+
stream.on("data", (chunk: Buffer) => {
601+
logger.info(`${chunk.toString()}`, { position: 'GitService', containerId: container.id });
602+
});
603+
600604
stream.on("end", () => {
601605
resolve({ stdout, stderr });
602606
});

0 commit comments

Comments
 (0)