Skip to content

Commit

Permalink
add retry type of policty
Browse files Browse the repository at this point in the history
  • Loading branch information
shotasilagadzetaal committed Sep 28, 2024
1 parent 1905473 commit a0f0c97
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pkg/metamorph/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,23 @@ func (m *Metamorph) SubmitTransaction(ctx context.Context, tx *sdkTx.Transaction
}, nil
}

response, err := m.client.PutTransaction(ctx, request)
if err != nil {
m.logger.Warn("Failed to submit transaction", slog.String("hash", tx.TxID()), slog.String("key", err.Error()))
if m.mqClient != nil {
err := m.mqClient.PublishMarshal(SubmitTxTopic, request)
if err != nil {
var response *metamorph_api.TransactionStatus
var err error
// in case of error try PutTransaction until timeout expires
for {
start := time.Now()
response, err = m.client.PutTransaction(ctx, request)
// Calculate duration
duration := time.Since(start).Seconds() + 1
if err != nil {
m.logger.Warn("Failed to submit transaction", slog.String("hash", tx.TxID()), slog.String("key", err.Error()))
if int64(duration) == request.GetMaxTimeout() {
return nil, err
}

return &TransactionStatus{
TxID: tx.TxID(),
Status: metamorph_api.Status_QUEUED.String(),
Timestamp: m.now().Unix(),
}, nil
request.MaxTimeout -= int64(duration)
} else {
break
}

return nil, err
}

return &TransactionStatus{
Expand Down

0 comments on commit a0f0c97

Please sign in to comment.