commit 1e9cc590694780e8363d109b1c88154fe78be4b1
parent 496c77967d7fbdc050ed978a9ad79709afc38d8d
Author: Joel-Haeberli <haebu@rubigen.ch>
Date: Sun, 2 Jun 2024 11:59:11 +0200
log: enhance logging
Diffstat:
2 files changed, 56 insertions(+), 63 deletions(-)
diff --git a/c2ec/proc-attestor.go b/c2ec/proc-attestor.go
@@ -142,22 +142,17 @@ func prepareRetryOrAbort(
errs chan error,
) {
- if CONFIG.Server.MaxRetries < 0 {
+ withdrawal, err := DB.GetWithdrawalById(withdrawalRowId)
+ if err != nil {
+ LogError("proc-attestor", err)
+ errs <- err
+ return
+ }
- lastRetryTs := time.Now().Unix()
- err := DB.SetLastRetry(withdrawalRowId, lastRetryTs)
- if err != nil {
- LogError("proc-attestor", err)
- }
+ if CONFIG.Server.MaxRetries < 0 {
+ prepareRetry(withdrawal, errs)
} else {
- withdrawal, err := DB.GetWithdrawalById(withdrawalRowId)
- if err != nil {
- LogError("proc-attestor", err)
- errs <- err
- return
- }
-
if withdrawal.RetryCounter >= CONFIG.Server.MaxRetries {
LogInfo("proc-attestor", fmt.Sprintf("max retries for withdrawal with id=%d was reached. withdrawal is aborted.", withdrawal.WithdrawalRowId))
@@ -166,12 +161,24 @@ func prepareRetryOrAbort(
LogError("proc-attestor", err)
}
} else {
-
- lastRetryTs := time.Now().Unix()
- err := DB.SetLastRetry(withdrawalRowId, lastRetryTs)
- if err != nil {
- LogError("proc-attestor", err)
- }
+ prepareRetry(withdrawal, errs)
}
}
}
+
+func prepareRetry(w *Withdrawal, errs chan error) {
+ // refactor this section to set retry counter and last retry field in one query...
+ err := DB.SetRetryCounter(int(w.WithdrawalRowId), int(w.RetryCounter)+1)
+ if err != nil {
+ LogError("proc-attestor", err)
+ errs <- err
+ return
+ }
+ lastRetryTs := time.Now().Unix()
+ err = DB.SetLastRetry(int(w.WithdrawalRowId), lastRetryTs)
+ if err != nil {
+ LogError("proc-attestor", err)
+ errs <- err
+ return
+ }
+}
diff --git a/c2ec/proc-retrier.go b/c2ec/proc-retrier.go
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
- "strconv"
"time"
)
@@ -13,13 +12,13 @@ const PS_RETRY_CHANNEL = "retry"
func RunRetrier(ctx context.Context, errs chan error) {
- go RunListener(
- ctx,
- PS_RETRY_CHANNEL,
- retryCallback,
- make(chan *Notification, RETRY_CHANNEL_BUFFER_SIZE),
- errs,
- )
+ // go RunListener(
+ // ctx,
+ // PS_RETRY_CHANNEL,
+ // retryCallback,
+ // make(chan *Notification, RETRY_CHANNEL_BUFFER_SIZE),
+ // errs,
+ // )
go func() {
lastlog := time.Now().Add(time.Minute * -3)
@@ -36,52 +35,46 @@ func RunRetrier(ctx context.Context, errs chan error) {
lastlog = time.Now()
}
for _, w := range withdrawals {
- var lastRetryTs int64 = 0
- if w.LastRetryTs != nil {
- lastRetryTs = *w.LastRetryTs
- if ShouldStartRetry(time.Unix(lastRetryTs, 0), int(w.RetryCounter), CONFIG.Server.RetryDelayMs) {
- LogInfo("proc-retries", "retrying for wopid="+encodeCrock(w.Wopid))
- attest(w, errs)
- }
- } else {
- LogInfo("proc-retrier", "first try confirming wopid="+encodeCrock(w.Wopid))
- attest(w, errs)
- }
+ retryOrSkip(w, errs)
}
}
}()
}
-func retryCallback(n *Notification, errs chan error) {
+// func retryCallback(n *Notification, errs chan error) {
- withdrawalId, err := strconv.Atoi(n.Payload)
- if err != nil {
- LogError("proc-retrier", err)
- errs <- err
- return
- }
+// withdrawalId, err := strconv.Atoi(n.Payload)
+// if err != nil {
+// LogError("proc-retrier", err)
+// errs <- err
+// return
+// }
- w, err := DB.GetWithdrawalById(withdrawalId)
- if err != nil {
- LogError("proc-retrier", err)
- errs <- err
- return
- }
+// w, err := DB.GetWithdrawalById(withdrawalId)
+// if err != nil {
+// LogError("proc-retrier", err)
+// errs <- err
+// return
+// }
+
+// retryOrSkip(w, errs)
+// }
+func retryOrSkip(w *Withdrawal, errs chan error) {
var lastRetryTs int64 = 0
if w.LastRetryTs != nil {
lastRetryTs = *w.LastRetryTs
if ShouldStartRetry(time.Unix(lastRetryTs, 0), int(w.RetryCounter), CONFIG.Server.RetryDelayMs) {
- LogInfo("proc-retries", "retrying for wopid="+encodeCrock(w.Wopid))
- attest(w, errs)
+ LogInfo("proc-retrier", "retrying for wopid="+encodeCrock(w.Wopid))
+ confirmRetryOrAbort(w, errs)
}
} else {
- LogInfo("proc-retrier", "first try confirming wopid="+encodeCrock(w.Wopid))
- attest(w, errs)
+ LogInfo("proc-retrier", "first retry confirming wopid="+encodeCrock(w.Wopid))
+ confirmRetryOrAbort(w, errs)
}
}
-func attest(withdrawal *Withdrawal, errs chan error) {
+func confirmRetryOrAbort(withdrawal *Withdrawal, errs chan error) {
if withdrawal == nil {
err := errors.New("withdrawal was null")
@@ -112,11 +105,4 @@ func attest(withdrawal *Withdrawal, errs chan error) {
}
finaliseOrSetRetry(transaction, int(withdrawal.WithdrawalRowId), errs)
-
- err = DB.SetRetryCounter(int(withdrawal.WithdrawalRowId), int(withdrawal.RetryCounter)+1)
- if err != nil {
- LogError("proc-retrier", err)
- errs <- err
- return
- }
}