feature: Refactors backend runtime's communication mechanism to be more stable.

This commit is contained in:
Tera << 8 2025-01-06 01:24:11 -05:00
parent 93f2f9cbee
commit 1e1a330a4b
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
10 changed files with 254 additions and 157 deletions

View file

@ -4,6 +4,9 @@ import (
"net"
"os/exec"
"strings"
"sync"
"github.com/charmbracelet/log"
)
type Backend struct {
@ -11,6 +14,11 @@ type Backend struct {
Path string `validate:"required"`
}
type messageForBuf struct {
Channel chan interface{}
Message interface{}
}
type Runtime struct {
isRuntimeRunning bool
logger *writeLogger
@ -18,9 +26,11 @@ type Runtime struct {
currentListener net.Listener
processRestartNotification chan bool
ProcessPath string
Logs []string
RuntimeCommands chan interface{}
messageBufferLock sync.Mutex
messageBuffer []*messageForBuf
ProcessPath string
Logs []string
OnCrashCallback func(sock net.Conn)
}
@ -31,6 +41,17 @@ type writeLogger struct {
func (writer writeLogger) Write(p []byte) (n int, err error) {
logSplit := strings.Split(string(p), "\n")
if isDevelopmentMode {
for _, logLine := range logSplit {
if logLine == "" {
continue
}
log.Debug("spawned backend logs: " + logLine)
}
}
writer.Runtime.Logs = append(writer.Runtime.Logs, logSplit...)
return len(p), err