From 077fc6af49da9f26f67ae423b17bcec9be10b9ad Mon Sep 17 00:00:00 2001 From: Sumeet Rai Date: Tue, 24 Sep 2024 12:43:16 +0530 Subject: [PATCH] invoke removal of cancel func after deletion from ES --- core/asset/service.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/asset/service.go b/core/asset/service.go index 7fe5b3ff..5645ec93 100644 --- a/core/asset/service.go +++ b/core/asset/service.go @@ -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 {