feat: refactor to ymsctl & yms-daemon
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package backendexecutor
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -62,6 +63,8 @@ type Request struct {
|
||||
ConfigLocation string
|
||||
RestartPolicy containerengine.RestartPolicy
|
||||
HealthEndpoint string
|
||||
StartLog bool
|
||||
LogReporter func(string)
|
||||
}
|
||||
|
||||
// Executor drives the persisted transaction up to SWITCHING after the new container is healthy.
|
||||
@@ -210,6 +213,21 @@ func (e *Executor) startAndCheck(ctx context.Context, transactionID string, requ
|
||||
if _, err := e.coordinator.ExecuteStep(ctx, transactionID, startIntent(request), startOperation); err != nil {
|
||||
return err
|
||||
}
|
||||
if request.StartLog && request.LogReporter != nil {
|
||||
logs, err := e.engine.ContainerLogs(ctx, request.ContainerName)
|
||||
if err == nil {
|
||||
scanner := bufio.NewScanner(logs)
|
||||
for scanner.Scan() {
|
||||
request.LogReporter(scanner.Text())
|
||||
}
|
||||
_ = logs.Close()
|
||||
if err := scanner.Err(); err != nil {
|
||||
return fmt.Errorf("read container startup logs: %w", err)
|
||||
}
|
||||
} else {
|
||||
request.LogReporter("unable to read container startup logs: " + err.Error())
|
||||
}
|
||||
}
|
||||
healthOperation := &healthOperation{
|
||||
engine: e.engine,
|
||||
checker: e.checker,
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@@ -408,6 +409,10 @@ func (e *fakeEngine) StartContainer(_ context.Context, name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *fakeEngine) ContainerLogs(context.Context, string) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader("")), nil
|
||||
}
|
||||
|
||||
func (e *fakeEngine) StopContainer(_ context.Context, name string) error {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user