Skip to content

Commit 1b66817

Browse files
committed
remove the snapshot to file loop
1 parent 45820dd commit 1b66817

2 files changed

Lines changed: 3 additions & 37 deletions

File tree

cmd/server/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,11 @@ var ServerCmd = &cobra.Command{
7676
logger.Error("Failed to parse agent type", "error", err)
7777
os.Exit(1)
7878
}
79-
process, cleanup, err := httpapi.SetupProcess(ctx, agent, argsToPass[1:]...)
79+
process, err := httpapi.SetupProcess(ctx, agent, argsToPass[1:]...)
8080
if err != nil {
8181
logger.Error("Failed to setup process", "error", err)
8282
os.Exit(1)
8383
}
84-
defer cleanup()
8584
srv := httpapi.NewServer(ctx, agentType, process, port)
8685
logger.Info("Starting server on port", "port", port)
8786
go func() {

lib/httpapi/setup.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77
"os/signal"
8-
"path/filepath"
98
"strings"
109
"syscall"
1110
"time"
@@ -14,7 +13,7 @@ import (
1413
"github.com/coder/agentapi/lib/termexec"
1514
)
1615

17-
func SetupProcess(ctx context.Context, program string, programArgs ...string) (*termexec.Process, func(), error) {
16+
func SetupProcess(ctx context.Context, program string, programArgs ...string) (*termexec.Process, error) {
1817
logger := logctx.From(ctx)
1918

2019
logger.Info(fmt.Sprintf("Running: %s %s", program, strings.Join(programArgs, " ")))
@@ -30,38 +29,6 @@ func SetupProcess(ctx context.Context, program string, programArgs ...string) (*
3029
os.Exit(1)
3130
}
3231

33-
snapshotFilePath := filepath.Join(".", fmt.Sprintf("snapshot-%s.log", time.Now().Format("20060102-150405")))
34-
snapshotFile, err := os.Create(snapshotFilePath)
35-
if err != nil {
36-
logger.Error(fmt.Sprintf("Error creating snapshot file: %v", err))
37-
os.Exit(1)
38-
}
39-
cleanup := func() {
40-
if err := snapshotFile.Close(); err != nil {
41-
logger.Error(fmt.Sprintf("Error closing snapshot file: %v", err))
42-
}
43-
}
44-
45-
go func() {
46-
logger.Info("Starting snapshot loop")
47-
for {
48-
time.Sleep(100 * time.Millisecond)
49-
// Truncate file and seek to beginning to overwrite completely
50-
if err := snapshotFile.Truncate(0); err != nil {
51-
logger.Error("Error truncating snapshot file", "error", err)
52-
os.Exit(1)
53-
}
54-
if _, err := snapshotFile.Seek(0, 0); err != nil {
55-
logger.Error("Error seeking in snapshot file", "error", err)
56-
os.Exit(1)
57-
}
58-
if _, err := snapshotFile.Write([]byte(process.ReadScreen())); err != nil {
59-
logger.Error("Error writing snapshot to file", "error", err)
60-
os.Exit(1)
61-
}
62-
}
63-
}()
64-
6532
// Handle SIGINT (Ctrl+C) and send it to the process
6633
signalCh := make(chan os.Signal, 1)
6734
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
@@ -72,5 +39,5 @@ func SetupProcess(ctx context.Context, program string, programArgs ...string) (*
7239
}
7340
}()
7441

75-
return process, cleanup, nil
42+
return process, nil
7643
}

0 commit comments

Comments
 (0)