forked from mtusi2026/mtusi2026lab4
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package media
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ReconcileMetadata combines bounded database inventory operations for the operator workflow.
|
|
type ReconcileMetadata interface {
|
|
Inventory
|
|
OrphanMetadata
|
|
}
|
|
|
|
// ReconcileObjects combines object inspection and listing for the operator workflow.
|
|
type ReconcileObjects interface {
|
|
ObjectInventory
|
|
OrphanObjects
|
|
}
|
|
|
|
// RunReconciliation emits one bounded result per page and stops on any uncertain dependency outcome.
|
|
func RunReconciliation(ctx context.Context, metadata ReconcileMetadata, objects ReconcileObjects, output io.Writer, apply bool) error {
|
|
encoder := json.NewEncoder(output)
|
|
after := uuid.Nil
|
|
for {
|
|
result, err := Reconcile(ctx, metadata, objects, after, time.Hour, apply)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := encoder.Encode(result); err != nil {
|
|
return err
|
|
}
|
|
if result.Scanned < 1000 {
|
|
break
|
|
}
|
|
after = result.Next
|
|
}
|
|
key := ""
|
|
for {
|
|
result, err := ReconcileOrphans(ctx, metadata, objects, key, time.Hour, apply)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := encoder.Encode(result); err != nil {
|
|
return err
|
|
}
|
|
if result.Scanned < 1000 {
|
|
return nil
|
|
}
|
|
key = result.Next
|
|
}
|
|
}
|