feature: Refactors backend runtime's communication mechanism to be more stable.
This commit is contained in:
parent
93f2f9cbee
commit
1e1a330a4b
10 changed files with 254 additions and 157 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue