Skip to content

Commit

Permalink
waiting for db from main
Browse files Browse the repository at this point in the history
  • Loading branch information
GrePod committed Dec 2, 2024
1 parent dffde55 commit 9f335b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 3 additions & 5 deletions client/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ func New(user *config.UserRaw, system *config.System, sharedDataPipes *shared.Da
// Run starts SigningPolicyInitializedListener, BitVoteListener, and AttestationRequestListener in go routines.
func (c *Collector) Run(ctx context.Context) {

WaitForDBToSync(ctx, c.DB)

go SigningPolicyInitializedListener(ctx, c.DB, c.RelayContractAddress, c.VoterRegistryContractAddress, c.SigningPolicies)
go AttestationRequestListener(ctx, c.DB, c.FdcContractAddress, requestListenerInterval, c.Requests)

Expand All @@ -134,13 +132,13 @@ func (c *Collector) Run(ctx context.Context) {
}

// WaitForDBToSync waits for db to sync. After many unsuccessful attempts it panics.
func WaitForDBToSync(ctx context.Context, db *gorm.DB) {
func (c *Collector) WaitForDBToSync(ctx context.Context) {
k := 0
for k < syncRetry {
if k > 0 {
logger.Debugf("Checking database for %v/%v time", k, syncRetry)
}
state, err := database.FetchState(ctx, db, nil)
state, err := database.FetchState(ctx, c.DB, nil)
if err != nil {
logger.Panic("database error:", err)
}
Expand All @@ -162,7 +160,7 @@ func WaitForDBToSync(ctx context.Context, db *gorm.DB) {
}

logger.Warnf("Checking database for the final time")
state, err := database.FetchState(ctx, db, nil)
state, err := database.FetchState(ctx, c.DB, nil)
if err != nil {
logger.Panic("database error:", err)
}
Expand Down
9 changes: 5 additions & 4 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ func main() {
sharedDataPipes := shared.NewDataPipes()

// Start attestation client collector
collector := collector.New(userConfigRaw, systemConfig, sharedDataPipes)
collector.Run(ctx)
col := collector.New(userConfigRaw, systemConfig, sharedDataPipes)
col.WaitForDBToSync(ctx)
go col.Run(ctx)

// Start attestation client manager
manager, err := manager.New(userConfigRaw, attestationTypeConfig, sharedDataPipes)
mngr, err := manager.New(userConfigRaw, attestationTypeConfig, sharedDataPipes)
if err != nil {
logger.Panicf("failed to create the manager: %s", err)
}
go manager.Run(ctx)
go mngr.Run(ctx)

// Run attestation client server
srv := server.New(&sharedDataPipes.Rounds, userConfigRaw.ProtocolID, userConfigRaw.RestServer)
Expand Down

0 comments on commit 9f335b0

Please sign in to comment.