Integrate cleanup into pipeline execution
This commit is contained in:
@@ -1,35 +1,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
func finalizeInvocation(runtime *invocationRuntime) (*RunSummary, error) {
|
||||
if containsStage(runtime.executed, "publish") {
|
||||
if err := runPostPublishCleanup(
|
||||
runtime.ctx,
|
||||
runtime.env,
|
||||
runtime.manifestPath,
|
||||
runtime.manifest,
|
||||
runtime.executed,
|
||||
runtime.dependencies.removeScopedDir,
|
||||
); err != nil {
|
||||
return nil, persistPostPublishCleanupFailure(
|
||||
runtime.ctx,
|
||||
runtime.manifestStore,
|
||||
runtime.manifestPath,
|
||||
runtime.manifest,
|
||||
fmt.Errorf("post-publish cleanup incomplete: %w", err),
|
||||
runtime.dependencies.now(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return &RunSummary{
|
||||
SessionID: runtime.identity.SessionID,
|
||||
RunID: runtime.identity.RunID,
|
||||
@@ -39,24 +10,3 @@ func finalizeInvocation(runtime *invocationRuntime) (*RunSummary, error) {
|
||||
Skipped: runtime.skipped,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func persistPostPublishCleanupFailure(
|
||||
ctx context.Context,
|
||||
sessionStore manifest.Store,
|
||||
sessionManifestPath string,
|
||||
sessionManifest *manifest.Manifest,
|
||||
operationErr error,
|
||||
at time.Time,
|
||||
) error {
|
||||
if operationErr == nil {
|
||||
return nil
|
||||
}
|
||||
if sessionManifest != nil {
|
||||
sessionManifest.RecordFailure(at, operationErr.Error())
|
||||
}
|
||||
// Cleanup may have deliberately removed the selected run directory. The
|
||||
// committed remote snapshot remains authoritative, while the session
|
||||
// manifest records the outstanding local cleanup for the next invocation.
|
||||
sessionErr := sessionStore.Save(ctx, sessionManifestPath, sessionManifest)
|
||||
return errors.Join(operationErr, wrapTerminalPersistenceError("save terminal session manifest", sessionErr))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user