add transaction for artifact delete (#16506)

Add transaction for artifact deletion, given API has the transaction when to call artifact controller but other object may not, for example jobservice job.
Here, force add the tx to ensure all the things can be rolled back.

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2022-03-11 14:40:55 +08:00 committed by GitHub
parent 6673841526
commit ef991ae0c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -311,7 +311,9 @@ func (c *controller) Delete(ctx context.Context, id int64) error {
if err != nil {
return err
}
return c.deleteDeeply(ctx, id, true, len(accs) > 0)
return orm.WithTransaction(func(ctx context.Context) error {
return c.deleteDeeply(ctx, id, true, len(accs) > 0)
})(orm.SetTransactionOpNameToContext(ctx, "tx-delete-artifact-delete"))
}
// "isRoot" is used to specify whether the artifact is the root parent artifact