Skip to content

Commit

Permalink
bug fix: avoid empty slice found error
Browse files Browse the repository at this point in the history
  • Loading branch information
iwehf committed Nov 6, 2024
1 parent e729804 commit f00de5e
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions tasks/sync_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ func processTaskStarted(block *types.Block, receipt *types.Receipt) error {

var existSelectedNodes []models.SelectedNode
if err := config.GetDB().Model(task).Association("SelectedNodes").Find(&existSelectedNodes); err != nil {
if err != gorm.ErrEmptySlice {
return err
}
return err
}
if len(existSelectedNodes) == 0 {
err := config.GetDB().Transaction(func(tx *gorm.DB) error {
Expand Down Expand Up @@ -533,26 +531,28 @@ func processTaskStarted(block *types.Block, receipt *types.Receipt) error {
}
}

err := config.GetDB().Transaction(func(tx *gorm.DB) error {
if err := tx.Model(task).Association("SelectedNodes").Append(newSelectedNodes); err != nil {
return err
}

var nodeStatusLogs []models.SelectedNodeStatusLog
for _, selectedNode := range newSelectedNodes {
nodeStatusLog := models.SelectedNodeStatusLog{
SelectedNode: selectedNode,
Status: models.NodeStatusPending,
if len(newSelectedNodes) > 0 {
err := config.GetDB().Transaction(func(tx *gorm.DB) error {
if err := tx.Model(task).Association("SelectedNodes").Append(newSelectedNodes); err != nil {
return err
}
nodeStatusLogs = append(nodeStatusLogs, nodeStatusLog)
}
if err := tx.Create(&nodeStatusLogs).Error; err != nil {

var nodeStatusLogs []models.SelectedNodeStatusLog
for _, selectedNode := range newSelectedNodes {
nodeStatusLog := models.SelectedNodeStatusLog{
SelectedNode: selectedNode,
Status: models.NodeStatusPending,
}
nodeStatusLogs = append(nodeStatusLogs, nodeStatusLog)
}
if err := tx.Create(&nodeStatusLogs).Error; err != nil {
return err
}
return nil
})
if err != nil {
return err
}
return nil
})
if err != nil {
return err
}
}

Expand Down

0 comments on commit f00de5e

Please sign in to comment.