refactor error handling in drip, flap, flop
This commit is contained in:
parent
05351a8ef4
commit
657aaccff3
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DripDripRepository struct {
|
type DripDripRepository struct {
|
||||||
@ -26,32 +27,41 @@ type DripDripRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripDripRepository) Create(headerID int64, models []interface{}) error {
|
func (repository DripDripRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
dripDrip, ok := model.(DripDripModel)
|
dripDrip, ok := model.(DripDripModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, DripDripModel{})
|
return fmt.Errorf("model of type %T, not %T", model, DripDripModel{})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, execErr := tx.Exec(
|
||||||
`INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log)
|
`INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2, $3, $4, $5)`,
|
VALUES($1, $2, $3, $4, $5)`,
|
||||||
headerID, dripDrip.Ilk, dripDrip.LogIndex, dripDrip.TransactionIndex, dripDrip.Raw,
|
headerID, dripDrip.Ilk, dripDrip.LogIndex, dripDrip.TransactionIndex, dripDrip.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DripFileIlkRepository struct {
|
type DripFileIlkRepository struct {
|
||||||
@ -26,34 +27,43 @@ type DripFileIlkRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
ilk, ok := model.(DripFileIlkModel)
|
ilk, ok := model.(DripFileIlkModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, DripFileIlkModel{})
|
return fmt.Errorf("model of type %T, not %T", model, DripFileIlkModel{})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, execErr := tx.Exec(
|
||||||
`INSERT into maker.drip_file_ilk (header_id, ilk, vow, tax, log_idx, tx_idx, raw_log)
|
`INSERT into maker.drip_file_ilk (header_id, ilk, vow, tax, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||||
headerID, ilk.Ilk, ilk.Vow, ilk.Tax, ilk.LogIndex, ilk.TransactionIndex, ilk.Raw,
|
headerID, ilk.Ilk, ilk.Vow, ilk.Tax, ilk.LogIndex, ilk.TransactionIndex, ilk.Raw,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DripFileRepoRepository struct {
|
type DripFileRepoRepository struct {
|
||||||
@ -26,34 +27,43 @@ type DripFileRepoRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
func (repository DripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
repo, ok := model.(DripFileRepoModel)
|
repo, ok := model.(DripFileRepoModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, DripFileRepoModel{})
|
return fmt.Errorf("model of type %T, not %T", model, DripFileRepoModel{})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, execErr := tx.Exec(
|
||||||
`INSERT into maker.drip_file_repo (header_id, what, data, log_idx, tx_idx, raw_log)
|
`INSERT into maker.drip_file_repo (header_id, what, data, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2, $3::NUMERIC, $4, $5, $6)`,
|
VALUES($1, $2, $3::NUMERIC, $4, $5, $6)`,
|
||||||
headerID, repo.What, repo.Data, repo.LogIndex, repo.TransactionIndex, repo.Raw,
|
headerID, repo.What, repo.Data, repo.LogIndex, repo.TransactionIndex, repo.Raw,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileRepoChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileRepoChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DripFileVowRepository struct {
|
type DripFileVowRepository struct {
|
||||||
@ -26,33 +27,42 @@ type DripFileVowRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository DripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
func (repository DripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vow, ok := model.(DripFileVowModel)
|
vow, ok := model.(DripFileVowModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, DripFileVowModel{})
|
return fmt.Errorf("model of type %T, not %T", model, DripFileVowModel{})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, execErr := tx.Exec(
|
||||||
`INSERT into maker.drip_file_vow (header_id, what, data, log_idx, tx_idx, raw_log)
|
`INSERT into maker.drip_file_vow (header_id, what, data, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2, $3, $4, $5, $6)`,
|
VALUES($1, $2, $3, $4, $5, $6)`,
|
||||||
headerID, vow.What, vow.Data, vow.LogIndex, vow.TransactionIndex, vow.Raw,
|
headerID, vow.What, vow.Data, vow.LogIndex, vow.TransactionIndex, vow.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileVowChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileVowChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FlapKickRepository struct {
|
type FlapKickRepository struct {
|
||||||
@ -26,9 +27,9 @@ type FlapKickRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository *FlapKickRepository) Create(headerID int64, models []interface{}) error {
|
func (repository *FlapKickRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
flapKickModel, ok := model.(FlapKickModel)
|
flapKickModel, ok := model.(FlapKickModel)
|
||||||
@ -36,21 +37,27 @@ func (repository *FlapKickRepository) Create(headerID int64, models []interface{
|
|||||||
return fmt.Errorf("model of type %T, not %T", model, FlapKickModel{})
|
return fmt.Errorf("model of type %T, not %T", model, FlapKickModel{})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, execErr := tx.Exec(
|
||||||
`INSERT into maker.flap_kick (header_id, bid_id, lot, bid, gal, "end", tx_idx, log_idx, raw_log)
|
`INSERT into maker.flap_kick (header_id, bid_id, lot, bid, gal, "end", tx_idx, log_idx, raw_log)
|
||||||
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8, $9)`,
|
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8, $9)`,
|
||||||
headerID, flapKickModel.BidId, flapKickModel.Lot, flapKickModel.Bid, flapKickModel.Gal, flapKickModel.End, flapKickModel.TransactionIndex, flapKickModel.LogIndex, flapKickModel.Raw,
|
headerID, flapKickModel.BidId, flapKickModel.Lot, flapKickModel.Bid, flapKickModel.Gal, flapKickModel.End, flapKickModel.TransactionIndex, flapKickModel.LogIndex, flapKickModel.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlapKickChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlapKickChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package flip_kick
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
@ -27,9 +28,9 @@ type FlipKickRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository FlipKickRepository) Create(headerID int64, models []interface{}) error {
|
func (repository FlipKickRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
flipKickModel, ok := model.(FlipKickModel)
|
flipKickModel, ok := model.(FlipKickModel)
|
||||||
@ -37,20 +38,26 @@ func (repository FlipKickRepository) Create(headerID int64, models []interface{}
|
|||||||
return fmt.Errorf("model of type %T, not %T", model, FlipKickModel{})
|
return fmt.Errorf("model of type %T, not %T", model, FlipKickModel{})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, execErr := tx.Exec(
|
||||||
`INSERT into maker.flip_kick (header_id, bid_id, lot, bid, gal, "end", urn, tab, tx_idx, log_idx, raw_log)
|
`INSERT into maker.flip_kick (header_id, bid_id, lot, bid, gal, "end", urn, tab, tx_idx, log_idx, raw_log)
|
||||||
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8::NUMERIC, $9, $10, $11)`,
|
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8::NUMERIC, $9, $10, $11)`,
|
||||||
headerID, flipKickModel.BidId, flipKickModel.Lot, flipKickModel.Bid, flipKickModel.Gal, flipKickModel.End, flipKickModel.Urn, flipKickModel.Tab, flipKickModel.TransactionIndex, flipKickModel.LogIndex, flipKickModel.Raw,
|
headerID, flipKickModel.BidId, flipKickModel.Lot, flipKickModel.Bid, flipKickModel.Gal, flipKickModel.End, flipKickModel.Urn, flipKickModel.Tab, flipKickModel.TransactionIndex, flipKickModel.LogIndex, flipKickModel.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlipKickChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlipKickChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FlopKickRepository struct {
|
type FlopKickRepository struct {
|
||||||
@ -26,9 +27,9 @@ type FlopKickRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository FlopKickRepository) Create(headerID int64, models []interface{}) error {
|
func (repository FlopKickRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, flopKick := range models {
|
for _, flopKick := range models {
|
||||||
flopKickModel, ok := flopKick.(Model)
|
flopKickModel, ok := flopKick.(Model)
|
||||||
@ -37,21 +38,27 @@ func (repository FlopKickRepository) Create(headerID int64, models []interface{}
|
|||||||
return fmt.Errorf("model of type %T, not %T", flopKick, Model{})
|
return fmt.Errorf("model of type %T, not %T", flopKick, Model{})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, execErr := tx.Exec(
|
||||||
`INSERT into maker.flop_kick (header_id, bid_id, lot, bid, gal, "end", tx_idx, log_idx, raw_log)
|
`INSERT into maker.flop_kick (header_id, bid_id, lot, bid, gal, "end", tx_idx, log_idx, raw_log)
|
||||||
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8, $9)`,
|
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8, $9)`,
|
||||||
headerID, flopKickModel.BidId, flopKickModel.Lot, flopKickModel.Bid, flopKickModel.Gal, flopKickModel.End, flopKickModel.TransactionIndex, flopKickModel.LogIndex, flopKickModel.Raw,
|
headerID, flopKickModel.BidId, flopKickModel.Lot, flopKickModel.Bid, flopKickModel.Gal, flopKickModel.End, flopKickModel.TransactionIndex, flopKickModel.LogIndex, flopKickModel.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlopKickChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlopKickChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
Loading…
Reference in New Issue
Block a user