You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2026/09/25 16:03:10 UTC
(airavata-custos) 01/05: Move the retry calculation logic into the events package
This is an automated email from the ASF dual-hosted git repository.
lahirujayathilake pushed a commit to branch persistent-event-bus
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 403108b456ea421131e168186b6d4759c5783eaa
Author: lahiruj <la...@gmail.com>
AuthorDate: Mon Sep 21 18:26:08 2026 -0400
Move the retry calculation logic into the events package
---
.../ACCESS/AMIE-Processor/worker/processor.go | 15 +++--------
pkg/events/backoff.go | 31 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/connectors/ACCESS/AMIE-Processor/worker/processor.go b/connectors/ACCESS/AMIE-Processor/worker/processor.go
index cce7c030b..f1126951d 100644
--- a/connectors/ACCESS/AMIE-Processor/worker/processor.go
+++ b/connectors/ACCESS/AMIE-Processor/worker/processor.go
@@ -33,6 +33,7 @@ import (
custosdb "github.com/apache/airavata-custos/connectors/ACCESS/AMIE-Processor/db"
"github.com/apache/airavata-custos/connectors/ACCESS/AMIE-Processor/model"
"github.com/apache/airavata-custos/internal/tracing"
+ "github.com/apache/airavata-custos/pkg/events"
)
const rootEventMaxBytes = 64 * 1024
@@ -323,16 +324,8 @@ func (p *Processor) recordFailureInNewTransaction(ctx context.Context, eventID s
})
}
-// ComputeNextRetryAt calculates the next retry time using exponential backoff.
-// The delay is BaseBackoffSeconds * 2^(attempt-1), capped at MaxBackoffSeconds.
+// ComputeNextRetryAt calculates the next retry time.
func ComputeNextRetryAt(attempt int) time.Time {
- exp := attempt - 1
- if exp < 0 {
- exp = 0
- }
- delaySec := BaseBackoffSeconds * (1 << exp) // 30 * 2^exp
- if delaySec > MaxBackoffSeconds {
- delaySec = MaxBackoffSeconds
- }
- return time.Now().UTC().Add(time.Duration(delaySec) * time.Second)
+ delay := events.NextRetryDelay(attempt, BaseBackoffSeconds*time.Second, MaxBackoffSeconds*time.Second)
+ return time.Now().UTC().Add(delay)
}
diff --git a/pkg/events/backoff.go b/pkg/events/backoff.go
new file mode 100644
index 000000000..133cbc093
--- /dev/null
+++ b/pkg/events/backoff.go
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package events
+
+import "time"
+
+// NextRetryDelay calculates the delay before the next retry using exponential backoff.
+// The delay starts at base, doubles per attempt, and is capped at max.
+func NextRetryDelay(attempt int, base, max time.Duration) time.Duration {
+ delay := base
+ // Stops doubling at the cap
+ for i := 1; i < attempt && delay < max; i++ {
+ delay *= 2
+ }
+ return min(delay, max)
+}