feat: complete remaining Go backend modules
This commit is contained in:
1 parent
cea2751dc5
commit
aef5a97165
145 files changed
+18376
-199
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package orchestration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/assets"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/jobs"
|
||||
)
|
||||
|
||||
type ScopedAssetDeleter interface {
|
||||
Delete(context.Context, assets.Scope, string) (assets.Asset, error)
|
||||
}
|
||||
|
||||
type AssetArtifacts struct{ assets ScopedAssetDeleter }
|
||||
|
||||
func NewAssetArtifacts(service ScopedAssetDeleter) *AssetArtifacts {
|
||||
return &AssetArtifacts{assets: service}
|
||||
}
|
||||
|
||||
// DeleteOutputs is retry-safe: already absent objects are treated as deleted,
|
||||
// while persistence/storage failures stop job deletion.
|
||||
func (adapter *AssetArtifacts) DeleteOutputs(ctx context.Context, job jobs.Job) ([]string, error) {
|
||||
if adapter == nil || adapter.assets == nil || job.OwnerID == "" {
|
||||
return nil, errors.New("delete generation output assets")
|
||||
}
|
||||
seen := make(map[string]bool, len(job.OutputAssetIDs))
|
||||
deleted := make([]string, 0, len(job.OutputAssetIDs))
|
||||
for _, id := range job.OutputAssetIDs {
|
||||
if id == "" || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
asset, err := adapter.assets.Delete(ctx, assets.PlatformScope(job.OwnerID), id)
|
||||
if errors.Is(err, assets.ErrNotFound) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.New("delete generation output assets")
|
||||
}
|
||||
deleted = append(deleted, asset.ID)
|
||||
}
|
||||
return deleted, nil
|
||||
}
|
||||
|
||||
var _ jobs.ArtifactDeleter = (*AssetArtifacts)(nil)
|
||||
Reference in new issue
Block a user