88 "fmt"
99 "os"
1010 "strings"
11+ "time"
1112
1213 "github.com/DIMO-Network/device-definitions-api/internal/contracts"
1314 "github.com/DIMO-Network/device-definitions-api/internal/core/common"
@@ -76,6 +77,8 @@ func (p *bulkUpdatePowertrain) Execute(ctx context.Context, _ *flag.FlagSet, _ .
7677 }
7778 onChainSvc := gateways .NewDeviceDefinitionOnChainService (& p .settings , & p .logger , ethClient , chainID , p .sender , pdb .DBS )
7879
80+ notFoundDefinitions := make ([]string , 0 )
81+
7982 for i , record := range records {
8083 if len (record ) < 2 {
8184 fmt .Printf ("Skipping malformed line %d: %v\n " , i + 1 , record )
@@ -93,13 +96,15 @@ func (p *bulkUpdatePowertrain) Execute(ctx context.Context, _ *flag.FlagSet, _ .
9396 }
9497 if len (strings .Split (definitionID , "_" )) != 3 {
9598 fmt .Printf ("Invalid definitionID: %s\n " , definitionID )
99+ notFoundDefinitions = append (notFoundDefinitions , definitionID )
96100 continue
97101 }
98102 fmt .Printf ("DefinitionID: %s, Powertrain: %s\n " , definitionID , powertrain )
99103
100104 deviceDefinition , manufID , err := onChainSvc .GetDefinitionByID (ctx , definitionID )
101105 if err != nil {
102106 fmt .Printf ("%s: Error getting device definition: %v\n " , definitionID , err )
107+ notFoundDefinitions = append (notFoundDefinitions , definitionID )
103108 continue
104109 }
105110
@@ -135,7 +140,14 @@ func (p *bulkUpdatePowertrain) Execute(ctx context.Context, _ *flag.FlagSet, _ .
135140 fmt .Printf ("%s: Error updating device definition: %v\n " , definitionID , err )
136141 return subcommands .ExitFailure
137142 }
138- fmt .Printf ("%s: Updated device definition trx id: %s\n " , definitionID , * update )
143+ fmt .Printf ("%s: Updated device definition trx id: %s\n Waiting 10 seconds before next update\n " , definitionID , * update )
144+
145+ time .Sleep (10 * time .Second )
146+ }
147+
148+ fmt .Printf ("Not found definitions: %d\n " , len (notFoundDefinitions ))
149+ for _ , definitionID := range notFoundDefinitions {
150+ fmt .Printf ("%s\n " , definitionID )
139151 }
140152
141153 return subcommands .ExitSuccess
0 commit comments