Separate session inspection collection from reporting
This commit is contained in:
96
internal/app/session_state_inspection.go
Normal file
96
internal/app/session_state_inspection.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
type localSessionInspection struct {
|
||||
manifest *manifest.Manifest
|
||||
manifestErr error
|
||||
catalog *artifacts.ArtifactCatalog
|
||||
catalogErr error
|
||||
definitions *artifactCatalogReport
|
||||
definitionsErr error
|
||||
}
|
||||
|
||||
func collectLocalSessionInspection(ctx context.Context, cfg *config.Config) localSessionInspection {
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
var out localSessionInspection
|
||||
out.manifest, out.manifestErr = loadLocalManifest(ctx, paths.ManifestPath)
|
||||
out.catalog, out.catalogErr = buildHelperArtifactCatalog(cfg, out.manifest)
|
||||
out.definitions, out.definitionsErr = describeArtifactDefinitions(cfg.Pipeline, cfg.ArtifactCatalog)
|
||||
return out
|
||||
}
|
||||
|
||||
type remoteSessionInspection struct {
|
||||
store storage.ObjectStore
|
||||
storeErr error
|
||||
current remoteCurrentStateCheck
|
||||
locks remoteLocksCheck
|
||||
state string
|
||||
outputs []sessionPublishedOutput
|
||||
outputsErr error
|
||||
}
|
||||
|
||||
func collectRemoteSessionInspection(ctx context.Context, cfg *config.Config, deps commandDependencies, local localSessionInspection) remoteSessionInspection {
|
||||
out := remoteSessionInspection{state: "not_configured", outputs: []sessionPublishedOutput{}}
|
||||
out.store, out.storeErr = objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
||||
if out.storeErr != nil {
|
||||
out.state = "error"
|
||||
return out
|
||||
}
|
||||
if out.store == nil {
|
||||
return out
|
||||
}
|
||||
out.current = inspectRemoteCurrentStateWithDependencies(ctx, cfg, out.store, deps)
|
||||
if out.current.Err != nil {
|
||||
if errors.Is(out.current.Err, artifacts.ErrCurrentCommitPointerMissing) {
|
||||
out.state = "missing"
|
||||
} else {
|
||||
out.state = "error"
|
||||
}
|
||||
} else if out.current.State != nil {
|
||||
out.state = "current"
|
||||
}
|
||||
out.locks = inspectRemoteLocks(ctx, cfg, out.store)
|
||||
if local.catalogErr == nil {
|
||||
out.outputs, out.outputsErr = inspectPublishedOutputs(ctx, cfg, out.store, local.catalog, out.current.State, out.locks.Locks, out.locks.Err == nil, out.state)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type sessionInputInspection struct {
|
||||
stable []stableInputCheck
|
||||
localAudio localAudioCheck
|
||||
remoteAudio *remoteAudioCheck
|
||||
effectiveErr, requirementsErr error
|
||||
previous previousArtifactReadiness
|
||||
}
|
||||
|
||||
func collectSessionInputInspection(ctx context.Context, cfg *config.Config, store storage.ObjectStore) sessionInputInspection {
|
||||
out := sessionInputInspection{stable: inspectStableInputs(cfg), localAudio: inspectLocalAudioPresence(cfg)}
|
||||
if cfg.Session.Inputs.AudioS3 != nil {
|
||||
audio := remoteAudioCheck{}
|
||||
if store != nil {
|
||||
audio = inspectRemoteAudioPresence(ctx, cfg, store)
|
||||
}
|
||||
out.remoteAudio = &audio
|
||||
}
|
||||
effective, err := resolveEffectiveArtifacts(cfg, nil)
|
||||
out.effectiveErr = err
|
||||
if err != nil {
|
||||
return out
|
||||
}
|
||||
requirements, err := artifacts.CollectPreviousArtifactRequirementsForConfig(cfg, effective)
|
||||
out.requirementsErr = err
|
||||
if err == nil {
|
||||
out.previous = inspectPreviousArtifactReadiness(ctx, cfg, store, requirements)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user