Skip to content

Commit

Permalink
fix: feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
boecklim committed Nov 19, 2024
1 parent 737d1df commit 2e2b11f
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions pkg/metamorph/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand All @@ -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()))
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()))
Expand All @@ -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)
Expand Down

0 comments on commit 2e2b11f

Please sign in to comment.