From 2e2b11f1417c7365ee483702182dcce2c6765dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=B6ckli?= Date: Tue, 19 Nov 2024 16:49:23 +0100 Subject: [PATCH] fix: feedback --- pkg/metamorph/client.go | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/pkg/metamorph/client.go b/pkg/metamorph/client.go index 272c4c7b6..da25835b3 100644 --- a/pkg/metamorph/client.go +++ b/pkg/metamorph/client.go @@ -245,13 +245,6 @@ func (m *Metamorph) SubmitTransaction(ctx context.Context, tx *sdkTx.Transaction var response *metamorph_api.TransactionStatus var err error - // in case of error try PutTransaction until timeout expires - - maxTimeout := max(time.Duration(request.MaxTimeout)*time.Second, m.maxTimeout) - - retryTicker := time.NewTicker(retryInterval) - - timeoutTimer := time.NewTimer(maxTimeout) response, err = m.client.PutTransaction(ctx, request) if err == nil { @@ -266,9 +259,15 @@ func (m *Metamorph) SubmitTransaction(ctx context.Context, tx *sdkTx.Transaction Timestamp: m.now().Unix(), }, nil } - m.logger.ErrorContext(ctx, "Failed to put transaction", slog.String("err", err.Error())) -forLoop: + + // in case of error try PutTransaction until timeout expires + + maxTimeout := max(time.Duration(request.MaxTimeout)*time.Second, m.maxTimeout) + retryTicker := time.NewTicker(retryInterval) + timeoutTimer := time.NewTimer(maxTimeout) + +retryLoop: for { select { case <-timeoutTimer.C: @@ -277,7 +276,7 @@ forLoop: case <-retryTicker.C: response, err = m.client.PutTransaction(ctx, request) if err == nil { - break forLoop + break retryLoop } m.logger.ErrorContext(ctx, "Failed to put transaction", slog.String("err", err.Error())) @@ -343,13 +342,6 @@ func (m *Metamorph) SubmitTransactions(ctx context.Context, txs sdkTx.Transactio var responses *metamorph_api.TransactionStatuses var err error - // put all transactions together - maxTimeout := max(time.Duration(in.Transactions[0].MaxTimeout)*time.Second, m.maxTimeout) - - retryTicker := time.NewTicker(retryInterval) - - timeoutTimer := time.NewTimer(maxTimeout) - responses, err = m.client.PutTransactions(ctx, in) if err == nil { // parse response and return to user @@ -369,9 +361,15 @@ func (m *Metamorph) SubmitTransactions(ctx context.Context, txs sdkTx.Transactio return ret, nil } - m.logger.ErrorContext(ctx, "Failed to put transactions", slog.String("err", err.Error())) -forLoop: + + // in case of error try PutTransaction until timeout expires + + maxTimeout := max(time.Duration(in.Transactions[0].MaxTimeout)*time.Second, m.maxTimeout) + retryTicker := time.NewTicker(retryInterval) + timeoutTimer := time.NewTimer(maxTimeout) + +retryLoop: for { select { case <-timeoutTimer.C: @@ -380,7 +378,7 @@ forLoop: case <-retryTicker.C: responses, err = m.client.PutTransactions(ctx, in) if err == nil { - break forLoop + break retryLoop } m.logger.ErrorContext(ctx, "Failed to put transactions", slog.String("err", err.Error())) @@ -396,7 +394,7 @@ forLoop: for _, tx := range txs { txStatus, getStatusErr := m.GetTransactionStatus(ctx, tx.TxID()) if getStatusErr != nil { - continue forLoop + continue retryLoop } txStatuses = append(txStatuses, txStatus)