Skip to content

Commit

Permalink
now do not close, continue forever
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Erwin committed Sep 23, 2024
1 parent 13672e8 commit 885acdf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
21 changes: 21 additions & 0 deletions new-backend/internal/ingestor/ingestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ func NewIngestor(logger *zap.Logger, sqlDB *sql.DB, apiKey string) *Ingestor {
return ingestor
}

func (i *Ingestor) StartContinuousIngestion(ctx context.Context) error {
for {
err := i.IngestTransactions(ctx)
if err != nil {
i.logger.Error("Error during transaction ingestion", zap.Error(err))
// Optionally, you might want to return the error here if you want to stop the process on errors
// return err
}

i.logger.Info("Finished ingestion cycle, waiting for 30 seconds before next check")

select {
case <-time.After(30 * time.Second):
// Continue to the next iteration after 30 seconds
case <-ctx.Done():
// Exit if the context is cancelled
return ctx.Err()
}
}
}

func (i *Ingestor) IngestTransactions(ctx context.Context) error {
startBlock, err := i.getStartBlock(ctx)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions new-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ func main() {

ingester := ingestor.NewIngestor(logger, db, os.Getenv("ETHERSCAN_API_KEY"))

if err := ingester.IngestTransactions(context.Background()); err != nil {
logger.Error("Fatal error in ingestor", zap.Error(err))
os.Exit(1)
ctx := context.Background()
if err := ingester.StartContinuousIngestion(ctx); err != nil {
log.Fatalf("Continuous ingestion stopped: %v", err)
}

logger.Info("Indexing completed successfully")
}

0 comments on commit 885acdf

Please sign in to comment.