cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

commit 64ee62d061ae652f713cbac938aa00ec41d83c16
parent d5c0b3a885ad522c2c6f8575f25ea0965fc43df1
Author: Joel-Haeberli <haebu@rubigen.ch>
Date:   Tue, 21 May 2024 23:43:49 +0200

fix: last retry will be set infinitely often

Diffstat:
Mc2ec/proc-attestor.go | 63++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/c2ec/proc-attestor.go b/c2ec/proc-attestor.go @@ -131,38 +131,47 @@ func finaliseOrSetRetry( prepareRetryOrAbort(withdrawalRowId, errs) } -// sets the last retry timestamp. +// Checks wether the maximal amount of retries was already +// reached and the withdrawal operation shall be aborted or +// triggers the next retry by setting the last_retry_ts field +// which will trigger the stored procedure triggering the retry +// process. The retry counter of the retries is handled by the +// retrier logic and shall not be set here! func prepareRetryOrAbort( withdrawalRowId int, errs chan error, ) { - // withdrawal, err := DB.GetWithdrawalById(withdrawalRowId) - // if err != nil { - // LogError("proc-attestor", err) - // errs <- err - // return - // } + if CONFIG.Server.MaxRetries < 0 { - lastRetryTs := time.Now().Unix() - err := DB.SetLastRetry(withdrawalRowId, lastRetryTs) - if err != nil { - LogError("proc-attestor", err) - } + lastRetryTs := time.Now().Unix() + err := DB.SetLastRetry(withdrawalRowId, lastRetryTs) + if err != nil { + LogError("proc-attestor", err) + } + } 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)) - // err := DB.FinaliseWithdrawal(withdrawalRowId, ABORTED, make([]byte, 0)) - // if err != nil { - // LogError("proc-attestor", err) - // } - // } else { - - // lastRetryTs := time.Now().Unix() - // err := DB.SetLastRetry(withdrawalRowId, lastRetryTs) - // if err != nil { - // LogError("proc-attestor", err) - // } - // } + 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)) + err := DB.FinaliseWithdrawal(withdrawalRowId, ABORTED, make([]byte, 0)) + if err != nil { + LogError("proc-attestor", err) + } + } else { + + lastRetryTs := time.Now().Unix() + err := DB.SetLastRetry(withdrawalRowId, lastRetryTs) + if err != nil { + LogError("proc-attestor", err) + } + } + } }