aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-26 17:19:13 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-26 17:19:13 +0100
commit60a59bcfdb3c2404a468cc314b7afde85ee35e1b (patch)
tree987589f2159cfe0335b8c2e70e05cb05e7d4f201
parentdcdee5e2aa05ec07e7e750bea4faad63bce7b668 (diff)
Don't send command output too fast.eel_5.0.1eel/5.0.15.0.1
Changes done in eows package of xds-common now allow to accumulate command output during a period of time (eg. 500ms) or up to the end of a line. Usage of this feature is mandatory to avoid to post to much buffers in websocket and consequently flood client (eg. web-browser) Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-rw-r--r--lib/xdsserver/sdk.go73
1 files changed, 13 insertions, 60 deletions
diff --git a/lib/xdsserver/sdk.go b/lib/xdsserver/sdk.go
index 633fbee..2736246 100644
--- a/lib/xdsserver/sdk.go
+++ b/lib/xdsserver/sdk.go
@@ -20,7 +20,6 @@ package xdsserver
import (
"encoding/json"
"fmt"
- "os"
"os/exec"
"path"
"strconv"
@@ -62,9 +61,6 @@ type CrossSDK struct {
scripts map[string]string
installCmd *eows.ExecOverWS
removeCmd *eows.ExecOverWS
-
- bufStdout string
- bufStderr string
}
// ListCrossSDK List all available and installed SDK (call "db-dump" script)
@@ -233,28 +229,13 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
// Create new instance to execute command and sent output over WS
s.installCmd = eows.New(s.scripts[scriptAdd], cmdArgs, sess.IOSocket, sess.ID, cmdID)
s.installCmd.Log = s.Log
+ s.installCmd.LineTimeSpan = 500 * time.Millisecond.Nanoseconds()
if timeout > 0 {
s.installCmd.CmdExecTimeout = timeout
} else {
s.installCmd.CmdExecTimeout = 30 * 60 // default 30min
}
- // FIXME: temporary hack
- s.bufStdout = ""
- s.bufStderr = ""
- SizeBufStdout := 10
- SizeBufStderr := 2000
- if valS, ok := os.LookupEnv("XDS_SDK_BUF_STDOUT"); ok {
- if valI, err := strconv.Atoi(valS); err == nil {
- SizeBufStdout = valI
- }
- }
- if valS, ok := os.LookupEnv("XDS_SDK_BUF_STDERR"); ok {
- if valI, err := strconv.Atoi(valS); err == nil {
- SizeBufStderr = valI
- }
- }
-
// Define callback for output (stdout+stderr)
s.installCmd.OutputCB = func(e *eows.ExecOverWS, stdout, stderr string) {
// paranoia
@@ -281,27 +262,18 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
}
}
- // Temporary "Hack": Buffered sent data to avoid freeze in web Browser
- // FIXME: remove bufStdout & bufStderr and implement better algorithm
- s.bufStdout += stdout
- s.bufStderr += stderr
- if len(s.bufStdout) > SizeBufStdout || len(s.bufStderr) > SizeBufStderr {
- // Emit event
- err := (*so).Emit(xsapiv1.EVTSDKManagement, xsapiv1.SDKManagementMsg{
- CmdID: e.CmdID,
- Timestamp: time.Now().String(),
- Action: xsapiv1.SdkMgtActionInstall,
- Sdk: s.sdk,
- Progress: 0, // TODO add progress
- Exited: false,
- Stdout: s.bufStdout,
- Stderr: s.bufStderr,
- })
- if err != nil {
- s.Log.Errorf("WS Emit : %v", err)
- }
- s.bufStdout = ""
- s.bufStderr = ""
+ err := (*so).Emit(xsapiv1.EVTSDKManagement, xsapiv1.SDKManagementMsg{
+ CmdID: e.CmdID,
+ Timestamp: time.Now().String(),
+ Action: xsapiv1.SdkMgtActionInstall,
+ Sdk: s.sdk,
+ Progress: 0, // TODO add progress
+ Exited: false,
+ Stdout: stdout,
+ Stderr: stderr,
+ })
+ if err != nil {
+ s.Log.Errorf("WS Emit : %v", err)
}
}
@@ -323,25 +295,6 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
return
}
- // Emit event remaining data in bufStdout/err
- if len(s.bufStderr) > 0 || len(s.bufStdout) > 0 {
- err := (*so).Emit(xsapiv1.EVTSDKManagement, xsapiv1.SDKManagementMsg{
- CmdID: e.CmdID,
- Timestamp: time.Now().String(),
- Action: xsapiv1.SdkMgtActionInstall,
- Sdk: s.sdk,
- Progress: 50, // TODO add progress
- Exited: false,
- Stdout: s.bufStdout,
- Stderr: s.bufStderr,
- })
- if err != nil {
- s.Log.Errorf("WS Emit : %v", err)
- }
- s.bufStdout = ""
- s.bufStderr = ""
- }
-
// Update SDK status
if code == 0 && exitError == nil {
s.sdk.LastError = ""