From 64d4820717765d4aa80a3123f21dbc3264a8511d Mon Sep 17 00:00:00 2001 From: Bolek Kulbabinski <1416262+bolekk@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:34:16 -0800 Subject: [PATCH] [KS-590] Auto-approval for workflow spec deletion --- core/services/feeds/service.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/services/feeds/service.go b/core/services/feeds/service.go index 61b2d53f2d5..3fe97241796 100644 --- a/core/services/feeds/service.go +++ b/core/services/feeds/service.go @@ -510,6 +510,21 @@ func (s *service) DeleteJob(ctx context.Context, args *DeleteJobArgs) (int64, er logger.Errorw("Failed to push metrics for job proposal deletion", "err", err) } + job, err := s.jobORM.FindJobByExternalJobID(ctx, proposal.ExternalJobID.UUID) + if err != nil { + // TODO: can this fails for non-workflow jobs? if so, should we still return an error (we don't know the type yet...) + return 0, errors.Wrap(err, "FindJobByExternalJobID failed") + } + if job.WorkflowSpecID != nil { + specId := int64(*job.WorkflowSpecID) + // auto approve workflow specs + if err := s.CancelSpec(ctx, specId); err != nil { + logger.Errorw("Failed to auto approve workflow spec deletion", "id", specId, "err", err) + return 0, fmt.Errorf("failed to approve workflow spec deletion %d: %w", specId, err) + } + logger.Infow("Successful workflow spec deletion auto approval", "id", specId) + } + return proposal.ID, nil }