feat: add status types to dispatcher

This commit is contained in:
Mohamed Sohail 2023-02-15 10:03:44 +03:00
parent 397cd78ca9
commit 05e1396121
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D

View File

@ -3,6 +3,7 @@ package task
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"github.com/celo-org/celo-blockchain/common" "github.com/celo-org/celo-blockchain/common"
"github.com/celo-org/celo-blockchain/core/types" "github.com/celo-org/celo-blockchain/core/types"
@ -21,8 +22,9 @@ type (
} }
dispatchEventPayload struct { dispatchEventPayload struct {
OtxId uint OtxId uint
TxHash string TxHash string
DispatchStatus status.Status
} }
) )
@ -54,8 +56,16 @@ func TxDispatch(
ctx, ctx,
eth.SendTx(p.Tx).Returns(&txHash), eth.SendTx(p.Tx).Returns(&txHash),
); err != nil { ); err != nil {
// TODO: Coreect error status switch err.Error() {
dispatchStatus.Status = status.FailGasPrice case celo.ErrGasPriceLow:
dispatchStatus.Status = status.FailGasPrice
case celo.ErrInsufficientGas:
dispatchStatus.Status = status.FailInsufficientGas
case celo.ErrNonceLow:
dispatchStatus.Status = status.FailNonce
default:
dispatchStatus.Status = status.Unknown
}
_, err := pg.CreateDispatchStatus(ctx, dispatchStatus) _, err := pg.CreateDispatchStatus(ctx, dispatchStatus)
if err != nil { if err != nil {
@ -72,7 +82,7 @@ func TxDispatch(
return err return err
} }
return err return fmt.Errorf("dispatch: failed %v: %w", err, asynq.SkipRetry)
} }
dispatchStatus.Status = status.Successful dispatchStatus.Status = status.Successful