feat(worker): add pipeline version upgrade command
This commit is contained in:
+39
-3
@@ -24,9 +24,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errConflictingReplayFlags = errors.New("replay and list-failed cannot be combined")
|
||||
errInvalidReplayID = errors.New("replay must be an attachment UUID")
|
||||
errMissingReplayAudit = errors.New("replay requires nonempty operator and reason")
|
||||
errConflictingReplayFlags = errors.New("replay and list-failed cannot be combined")
|
||||
errInvalidReplayID = errors.New("replay must be an attachment UUID")
|
||||
errMissingReplayAudit = errors.New("replay requires nonempty operator and reason")
|
||||
errConflictingUpgradeFlags = errors.New("upgrade cannot be combined with replay or list-failed")
|
||||
errInvalidUpgradeID = errors.New("upgrade must be an attachment UUID")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -36,6 +38,7 @@ func main() {
|
||||
operator := flag.String("operator", "", "operator requesting replay")
|
||||
reason := flag.String("reason", "", "reason for replay")
|
||||
listFailed := flag.Bool("list-failed", false, "list up to 100 failed attachments")
|
||||
upgrade := flag.String("upgrade", "", "upgrade a v1 queued or processing attachment to v2; requires retained staging")
|
||||
flag.Parse()
|
||||
|
||||
if *maxPixels > 0 {
|
||||
@@ -56,12 +59,16 @@ func main() {
|
||||
|
||||
var err error
|
||||
switch {
|
||||
case *upgrade != "" && (*listFailed || *replay != ""):
|
||||
err = errConflictingUpgradeFlags
|
||||
case *listFailed && *replay != "":
|
||||
err = errConflictingReplayFlags
|
||||
case *listFailed:
|
||||
err = runListFailed(ctx)
|
||||
case *replay != "":
|
||||
err = runReplay(ctx, *replay, *operator, *reason)
|
||||
case *upgrade != "":
|
||||
err = runUpgrade(ctx, *upgrade)
|
||||
default:
|
||||
err = runWorker(ctx)
|
||||
}
|
||||
@@ -133,6 +140,35 @@ func runReplay(ctx context.Context, replay, operator, reason string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func runUpgrade(ctx context.Context, upgrade string) error {
|
||||
id, err := uuid.Parse(upgrade)
|
||||
if err != nil {
|
||||
return errInvalidUpgradeID
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
cfg, pool, err := loadDatabase(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
log := logger.New(cfg.Logging.Level)
|
||||
storage, err := s3store.NewAPI(ctx, cfg.S3, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := worker.Upgrade(ctx, pool, storage, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("attachment pipeline upgrade queued", "attachment_id", id, "pipeline_version", 2)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runWorker(ctx context.Context) error {
|
||||
cfg, pool, err := loadDatabase(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user