Controller Liveliness Query Split (#5602)

* Initial Update Controller Call And Sample Test

* Update Controller Start Logic To Upsert

* Chore Make Gen

* Lowercase User For GCP Instance Label

* Resolve Comments
This commit is contained in:
Ryan Derr authored and GitHub committed 2025-03-17 14:04:40 -05:00
1 parent 6d8615045e
commit 6c0b3a8a1c
3 files changed
+202 -2

No files matched your search

+37
View File
@@ -77,3 +77,40 @@ func (r *Repository) UpsertController(ctx context.Context, controller *store.Con
return int(rowsUpdated), nil
}
func (r *Repository) UpdateController(ctx context.Context, controller *store.Controller) (int, error) {
const op = "server.(Repository).UpdateController"
if controller == nil {
return db.NoRowsAffected, errors.New(ctx, errors.InvalidParameter, op, "controller is nil")
}
if controller.PrivateId == "" {
return db.NoRowsAffected, errors.New(ctx, errors.InvalidParameter, op, "controller private_id is empty")
}
if controller.Address == "" {
return db.NoRowsAffected, errors.New(ctx, errors.InvalidParameter, op, "controller address is empty")
}
var rowsUpdated int
_, err := r.writer.DoTx(
ctx,
db.StdRetryCnt,
db.ExpBackoff{},
func(reader db.Reader, w db.Writer) error {
var err error
rowsUpdated, err = w.Update(ctx, controller, []string{"description", "address"}, nil, db.WithWhere("private_id = ?", controller.PrivateId))
if err != nil {
return errors.Wrap(ctx, err, op+":Update")
}
if rowsUpdated > 1 {
return errors.New(ctx, errors.MultipleRecords, op, "more than 1 resource would have been updated")
}
return nil
},
)
if err != nil {
return db.NoRowsAffected, err
}
return rowsUpdated, nil
}