fix (byow): minor updates to UpsertWorkerStatus(...) on conflict (#2194)

pull/2197/head
Jim 4 years ago committed by GitHub
parent 11b025c016
commit d7aaa9f7e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -277,8 +277,17 @@ func (r *Repository) UpsertWorkerStatus(ctx context.Context, worker *Worker, opt
Action: append(db.SetColumns([]string{"address"}),
db.SetColumnValues(map[string]interface{}{"last_status_time": "now()"})...),
}
if err := w.Create(ctx, worker, db.WithOnConflict(workerCreateConflict)); err != nil {
var withRowsAffected int64
err := w.Create(ctx, worker, db.WithOnConflict(workerCreateConflict), db.WithReturnRowsAffected(&withRowsAffected),
// The intent of this WithWhere option is to operate with the OnConflict such that the action
// taken by the OnConflict only applies if the conflict is on a row that is returned by this where
// statement, otherwise it should error out.
db.WithWhere("server_worker.type = 'kms'"))
switch {
case err != nil:
return errors.Wrap(ctx, err, op, errors.WithMsg("error creating a worker"))
case withRowsAffected == 0:
return errors.New(ctx, errors.NotUnique, op, "error updating worker")
}
case opts.withKeyId != "":
n, err := w.Update(ctx, worker, []string{"address"}, nil)

Loading…
Cancel
Save