Skip to content

Commit

Permalink
invoke removal of cancel func after deletion from ES
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumeet Rai committed Sep 24, 2024
1 parent c62d999 commit 077fc6a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/asset/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,23 @@ func (s *Service) DeleteAssets(ctx context.Context, request DeleteAssetsRequest)

if !request.DryRun && total > 0 {
newCtx, cancel := context.WithTimeout(context.Background(), s.config.DeleteAssetsTimeout)
idx := len(s.cancelFnList)
s.cancelFnList = append(s.cancelFnList, cancel)
go s.executeDeleteAssets(newCtx, deleteSQLExpr)
go func(index int) {
s.executeDeleteAssets(newCtx, deleteSQLExpr)
s.removeCancelFnByIndex(index)
}(idx)
}

return uint32(total), nil
}

func (s *Service) removeCancelFnByIndex(index int) {
if index < len(s.cancelFnList) {
s.cancelFnList = append(s.cancelFnList[:index], s.cancelFnList[index+1:]...)
}
}

func (s *Service) executeDeleteAssets(ctx context.Context, deleteSQLExpr queryexpr.ExprStr) {
deletedURNs, err := s.assetRepository.DeleteByQueryExpr(ctx, deleteSQLExpr)
if err != nil {
Expand Down

0 comments on commit 077fc6a

Please sign in to comment.