111 lines
3.5 KiB
Go
111 lines
3.5 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"sort"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
"go.maximumdirect.net/commandkit"
|
|
)
|
|
|
|
// Status reports effective local/remote session state.
|
|
func Status(ctx context.Context, args []string, out io.Writer) error {
|
|
return statusWithDependencies(ctx, args, out, commandDependencies{})
|
|
}
|
|
|
|
func statusWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
|
deps = normalizeCommandDependencies(deps)
|
|
fs := flag.NewFlagSet("status", flag.ContinueOnError)
|
|
fs.SetOutput(io.Discard)
|
|
var flags commonConfigFlags
|
|
addCommonConfigFlags(fs, &flags)
|
|
if err := parseSessionAwareFlags("status", fs, args, &flags.sessionID); err != nil {
|
|
return err
|
|
}
|
|
if strings.TrimSpace(flags.sessionID) == "" {
|
|
return fmt.Errorf("status: session_id is required")
|
|
}
|
|
loaded, err := loadCommandConfigWithDependencies(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions(), flags.secretsDir.pointer(), deps)
|
|
if err != nil {
|
|
return fmt.Errorf("status: %w", err)
|
|
}
|
|
defer func() { _ = loaded.Close() }()
|
|
cfg := loaded.Config
|
|
report, err := inspectSessionState(ctx, cfg, true, true, deps)
|
|
if report != nil {
|
|
err = errors.Join(err, commandkit.RenderReport(out, commandkit.Report{Value: report}, ""))
|
|
}
|
|
return err
|
|
}
|
|
|
|
func writeStatusStableInputs(out io.Writer, checks []stableInputCheck) {
|
|
if len(checks) == 0 {
|
|
return
|
|
}
|
|
for _, check := range checks {
|
|
if check.Err != nil {
|
|
if strings.TrimSpace(check.Path) != "" {
|
|
fmt.Fprintf(out, "Stable input %s: unavailable: %v\n", check.Name, check.Err)
|
|
} else {
|
|
fmt.Fprintf(out, "Stable input %s: unavailable: %s\n", check.Name, check.Err.Error())
|
|
}
|
|
continue
|
|
}
|
|
fmt.Fprintf(out, "Stable input %s: %s\n", check.Name, check.Path)
|
|
}
|
|
}
|
|
|
|
func writeStatusLocalAudio(out io.Writer, check localAudioCheck) {
|
|
if !check.Checked {
|
|
return
|
|
}
|
|
if check.Err != nil {
|
|
fmt.Fprintf(out, "Local audio: unavailable: %v\n", check.Err)
|
|
return
|
|
}
|
|
fmt.Fprintf(out, "Local audio: %d file(s)\n", len(check.Paths))
|
|
}
|
|
|
|
func writeStatusRemoteAudio(ctx context.Context, out io.Writer, cfg *config.Config, store storage.ObjectStore, storeErr error) {
|
|
if cfg.Session.Inputs.AudioS3 == nil {
|
|
return
|
|
}
|
|
if storeErr != nil {
|
|
fmt.Fprintf(out, "Remote audio: unavailable: %v\n", storeErr)
|
|
return
|
|
}
|
|
check := inspectRemoteAudioPresence(ctx, cfg, store)
|
|
if check.Err != nil {
|
|
fmt.Fprintf(out, "Remote audio: unavailable: %v\n", check.Err)
|
|
return
|
|
}
|
|
fmt.Fprintf(out, "Remote audio: %d .flac object(s)\n", len(check.Keys))
|
|
}
|
|
|
|
func writeStatusPreviousArtifacts(out io.Writer, readiness previousArtifactReadiness) {
|
|
if len(readiness.Requirements) == 0 {
|
|
fmt.Fprintln(out, "Previous-session artifacts: not required")
|
|
return
|
|
}
|
|
if readiness.Err != nil {
|
|
fmt.Fprintf(out, "Previous-session artifacts: unavailable: %v\n", readiness.Err)
|
|
return
|
|
}
|
|
names := make([]string, 0, len(readiness.Requirements))
|
|
for _, req := range readiness.Requirements {
|
|
names = append(names, fmt.Sprintf("%s(required=%t)", req.Name, req.Required))
|
|
}
|
|
sort.Strings(names)
|
|
if len(readiness.SkippedMissing) > 0 {
|
|
fmt.Fprintf(out, "Previous-session artifacts: ready: %s; optional unavailable: %s\n", strings.Join(names, ", "), strings.Join(readiness.SkippedMissing, ", "))
|
|
return
|
|
}
|
|
fmt.Fprintf(out, "Previous-session artifacts: ready: %s\n", strings.Join(names, ", "))
|
|
}
|