backend version, check telemetry send more often (but send on the same interval) -- works better with computer suspend.

This commit is contained in:
sawka 2023-01-25 22:49:50 -08:00
parent 518e900403
commit 848f321ae7
2 changed files with 20 additions and 9 deletions

View File

@ -43,6 +43,10 @@ const WebSocketServerDevAddr = "localhost:8091"
const WSStateReconnectTime = 30 * time.Second
const WSStatePacketChSize = 20
const InitialTelemetryWait = 30 * time.Second
const TelemetryTick = 30 * time.Minute
const TelemetryInterval = 8 * time.Hour
var GlobalLock = &sync.Mutex{}
var WSStateMap = make(map[string]*scws.WSState) // clientid -> WsState
var GlobalAuthKey string
@ -424,6 +428,19 @@ func sendTelemetryWrapper() {
}
}
func telemetryLoop() {
var lastSent time.Time
time.Sleep(InitialTelemetryWait)
for {
dur := time.Now().Sub(lastSent)
if lastSent.IsZero() || dur >= TelemetryInterval {
lastSent = time.Now()
sendTelemetryWrapper()
}
time.Sleep(TelemetryTick)
}
}
// watch stdin, kill server if stdin is closed
func stdinReadWatch() {
buf := make([]byte, 1024)
@ -509,15 +526,8 @@ func main() {
log.Printf("[error] resetting window focus: %v\n", err)
}
go func() {
log.Printf("PCLOUD_ENDPOINT=%s\n", pcloud.GetEndpoint())
time.Sleep(30 * time.Second)
for {
sendTelemetryWrapper()
// send new telemetry every 8-hours
time.Sleep(8 * time.Hour)
}
}()
log.Printf("PCLOUD_ENDPOINT=%s\n", pcloud.GetEndpoint())
go telemetryLoop()
go stdinReadWatch()
go runWebSocketServer()
gr := mux.NewRouter()

View File

@ -2106,6 +2106,7 @@ func ClientShowCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (s
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf(" %-15s %s\n", "userid", clientData.UserId))
buf.WriteString(fmt.Sprintf(" %-15s %s\n", "clientid", clientData.ClientId))
buf.WriteString(fmt.Sprintf(" %-15s %s\n", "backend", scbase.PromptVersion))
buf.WriteString(fmt.Sprintf(" %-15s %s\n", "telemetry", boolToStr(clientData.ClientOpts.NoTelemetry, "off", "on")))
update := sstore.ModelUpdate{
Info: &sstore.InfoMsgType{