Skip to content

Commit 077fc6a

Browse files
author
Sumeet Rai
committed
invoke removal of cancel func after deletion from ES
1 parent c62d999 commit 077fc6a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: core/asset/service.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,23 @@ func (s *Service) DeleteAssets(ctx context.Context, request DeleteAssetsRequest)
154154

155155
if !request.DryRun && total > 0 {
156156
newCtx, cancel := context.WithTimeout(context.Background(), s.config.DeleteAssetsTimeout)
157+
idx := len(s.cancelFnList)
157158
s.cancelFnList = append(s.cancelFnList, cancel)
158-
go s.executeDeleteAssets(newCtx, deleteSQLExpr)
159+
go func(index int) {
160+
s.executeDeleteAssets(newCtx, deleteSQLExpr)
161+
s.removeCancelFnByIndex(index)
162+
}(idx)
159163
}
160164

161165
return uint32(total), nil
162166
}
163167

168+
func (s *Service) removeCancelFnByIndex(index int) {
169+
if index < len(s.cancelFnList) {
170+
s.cancelFnList = append(s.cancelFnList[:index], s.cancelFnList[index+1:]...)
171+
}
172+
}
173+
164174
func (s *Service) executeDeleteAssets(ctx context.Context, deleteSQLExpr queryexpr.ExprStr) {
165175
deletedURNs, err := s.assetRepository.DeleteByQueryExpr(ctx, deleteSQLExpr)
166176
if err != nil {

0 commit comments

Comments
 (0)