forked from mtusi2026/mtusi2026lab4
38 lines
995 B
Go
38 lines
995 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"os"
|
|
"time"
|
|
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab4/internal/config"
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab4/internal/media"
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab4/internal/objectstore"
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab4/internal/store/postgres"
|
|
)
|
|
|
|
// reconcile runs a bounded dry-run scan unless the operator explicitly supplies apply.
|
|
func reconcile(apply bool) error {
|
|
cfg, err := config.NewPersistence()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s3, err := config.NewObjectStore()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
database, err := postgres.New(postgres.Options{URL: cfg.DatabaseURL, MaxConnections: 1, Timeout: 5 * time.Second})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer database.Close()
|
|
objects, err := objectstore.New(s3)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
|
defer cancel()
|
|
return media.RunReconciliation(ctx, database, objects, os.Stdout, apply)
|
|
}
|