From 2237ce41eb5faed98e3aa1324ffe1bfb7fd8688d Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 23 Mar 2024 18:14:17 -0400 Subject: [PATCH] feat: postpone sandbox grpc connection time --- internal/executors/sandbox/executor.go | 8 ++++++-- internal/executors/sandbox/meta.go | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/executors/sandbox/executor.go b/internal/executors/sandbox/executor.go index 6a61022..df01796 100644 --- a/internal/executors/sandbox/executor.go +++ b/internal/executors/sandbox/executor.go @@ -10,11 +10,15 @@ import ( ) type Sandbox struct { - execClient pb.ExecutorClient - cachedMap map[string]string + execServer, token string + cachedMap map[string]string + execClient pb.ExecutorClient } func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { + if e.execClient == nil { + e.execClient = createExecClient(e.execServer, e.token) + } // cannot use range loop since we need to change the value for i := 0; i < len(cmds); i++ { cmd := &cmds[i] diff --git a/internal/executors/sandbox/meta.go b/internal/executors/sandbox/meta.go index c22b750..2702646 100644 --- a/internal/executors/sandbox/meta.go +++ b/internal/executors/sandbox/meta.go @@ -9,7 +9,8 @@ var name = "sandbox" func init() { stage.RegisterExecutor(name, &Sandbox{ // TODO: read from conf - execClient: createExecClient("localhost:5051", ""), + execServer: "localhost:5051", + token: "", cachedMap: make(map[string]string), }) }