From df69d3914642fc6bd398c16b46794d963f6e4c2c Mon Sep 17 00:00:00 2001 From: kakcy Date: Tue, 6 Aug 2024 11:16:22 +0900 Subject: [PATCH] chore: revert IsCompleted --- pkg/autoops/api/api.go | 4 ++-- pkg/autoops/domain/auto_ops_rule.go | 4 ---- pkg/autoops/domain/auto_ops_rule_test.go | 12 ------------ pkg/batch/jobs/opsevent/datetime_watcher.go | 2 +- pkg/batch/jobs/opsevent/event_count_watcher.go | 2 +- .../subscriber/processor/evaluation_events_ops.go | 3 ++- pkg/batch/subscriber/processor/goal_events_ops.go | 2 +- 7 files changed, 7 insertions(+), 22 deletions(-) diff --git a/pkg/autoops/api/api.go b/pkg/autoops/api/api.go index 9e8b04303..65579a736 100644 --- a/pkg/autoops/api/api.go +++ b/pkg/autoops/api/api.go @@ -706,7 +706,7 @@ func (s *AutoOpsService) UpdateAutoOpsRule( return err } - if autoOpsRule.IsCompleted() { + if autoOpsRule.IsFinished() || autoOpsRule.IsStopped() { dt, err := statusAutoOpsRuleCompleted.WithDetails(&errdetails.LocalizedMessage{ Locale: localizer.GetLocale(), Message: localizer.MustLocalize(locale.InvalidArgumentError), @@ -1491,7 +1491,7 @@ func (s *AutoOpsService) checkIfHasAlreadyTriggered( } return false, dt.Err() } - if autoOpsRule.IsCompleted() || autoOpsRule.Deleted { + if autoOpsRule.IsFinished() || autoOpsRule.IsStopped() || autoOpsRule.Deleted { s.logger.Warn( "Auto Ops Rule already triggered", log.FieldsFromImcomingContext(ctx).AddFields( diff --git a/pkg/autoops/domain/auto_ops_rule.go b/pkg/autoops/domain/auto_ops_rule.go index dda9fe2dd..b96b032ae 100644 --- a/pkg/autoops/domain/auto_ops_rule.go +++ b/pkg/autoops/domain/auto_ops_rule.go @@ -120,10 +120,6 @@ func (a *AutoOpsRule) IsStopped() bool { return a.AutoOpsStatus == proto.AutoOpsStatus_STOPPED } -func (a *AutoOpsRule) IsCompleted() bool { - return a.IsFinished() || a.IsStopped() -} - func (a *AutoOpsRule) SetOpsType(opsType proto.OpsType) { a.AutoOpsRule.OpsType = opsType a.AutoOpsRule.UpdatedAt = time.Now().Unix() diff --git a/pkg/autoops/domain/auto_ops_rule_test.go b/pkg/autoops/domain/auto_ops_rule_test.go index 25197d8ba..33155668c 100644 --- a/pkg/autoops/domain/auto_ops_rule_test.go +++ b/pkg/autoops/domain/auto_ops_rule_test.go @@ -495,18 +495,6 @@ func TestIsStopped(t *testing.T) { assert.True(t, aor.IsStopped()) } -func TestIsCompleted(t *testing.T) { - t.Parallel() - aor := createAutoOpsRule(t) - assert.False(t, aor.IsCompleted()) - - aor.AutoOpsStatus = autoopsproto.AutoOpsStatus_STOPPED - assert.True(t, aor.IsCompleted()) - - aor.AutoOpsStatus = autoopsproto.AutoOpsStatus_FINISHED - assert.True(t, aor.IsCompleted()) -} - func TestSetAutoOpsStatus(t *testing.T) { t.Parallel() aor := createAutoOpsRule(t) diff --git a/pkg/batch/jobs/opsevent/datetime_watcher.go b/pkg/batch/jobs/opsevent/datetime_watcher.go index 87161bb6f..a3d8e657e 100644 --- a/pkg/batch/jobs/opsevent/datetime_watcher.go +++ b/pkg/batch/jobs/opsevent/datetime_watcher.go @@ -76,7 +76,7 @@ func (w *datetimeWatcher) Run(ctx context.Context) (lastErr error) { } for _, a := range autoOpsRules { aor := &autoopsdomain.AutoOpsRule{AutoOpsRule: a} - if aor.IsCompleted() { + if aor.IsFinished() || aor.IsStopped() { continue } executeClauseID, err := w.getExecuteClauseId(ctx, env.Id, aor) diff --git a/pkg/batch/jobs/opsevent/event_count_watcher.go b/pkg/batch/jobs/opsevent/event_count_watcher.go index 9a2bfcd15..9b256ae61 100644 --- a/pkg/batch/jobs/opsevent/event_count_watcher.go +++ b/pkg/batch/jobs/opsevent/event_count_watcher.go @@ -92,7 +92,7 @@ func (w *eventCountWatcher) Run(ctx context.Context) (lastErr error) { } for _, a := range autoOpsRules { aor := &autoopsdomain.AutoOpsRule{AutoOpsRule: a} - if aor.IsCompleted() { + if aor.IsFinished() || aor.IsStopped() { continue } executeId, err := w.getExecuteClauseId(ctx, env.Id, aor) diff --git a/pkg/batch/subscriber/processor/evaluation_events_ops.go b/pkg/batch/subscriber/processor/evaluation_events_ops.go index d786fba3c..a38150984 100644 --- a/pkg/batch/subscriber/processor/evaluation_events_ops.go +++ b/pkg/batch/subscriber/processor/evaluation_events_ops.go @@ -191,7 +191,8 @@ func (u *evalEvtUpdater) linkOpsRulesByFeatureID( for _, aor := range listAutoOpsRules { r := &aodomain.AutoOpsRule{AutoOpsRule: aor} // Ignore already triggered ops rules - if aor.FeatureId == featureID && !r.IsCompleted() { + if aor.FeatureId == featureID && + !(r.IsFinished() || r.IsStopped()) { rules = append(rules, aor) } } diff --git a/pkg/batch/subscriber/processor/goal_events_ops.go b/pkg/batch/subscriber/processor/goal_events_ops.go index e2da318c8..0ea5bd6a0 100644 --- a/pkg/batch/subscriber/processor/goal_events_ops.go +++ b/pkg/batch/subscriber/processor/goal_events_ops.go @@ -221,7 +221,7 @@ func (u *evalGoalUpdater) linkOpsRulesByGoalID( for _, aor := range listAutoOpsRules { autoOpsRule := &aodomain.AutoOpsRule{AutoOpsRule: aor} // We ignore the rules that are already triggered - if autoOpsRule.IsCompleted() { + if autoOpsRule.IsFinished() || autoOpsRule.IsStopped() { continue } clauses, err := autoOpsRule.ExtractOpsEventRateClauses()