Skip to content

Commit

Permalink
chore: add more functionality to recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Jul 24, 2023
1 parent 10332cb commit b396c66
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type configType struct {
// Routines
RoutinesRunOnly bool `envconfig:"ROUTINES_RUN_ONLY" required:"false" default:"false"`
RoutinesSleepDuration time.Duration `envconfig:"ROUTINES_SLEEP_DURATION" required:"false" default:"1h"`
RoutinesBatchSize int `envconfig:"ROUTINES_BATCH_SIZE" required:"false" default:"1000"`
RoutinesBatchSize int `envconfig:"ROUTINES_BATCH_SIZE" required:"false" default:"10"`
RoutinesNumWorkers int `envconfig:"ROUTINES_NUM_WORKERS" required:"false" default:"1"`

// FindMissing
Expand All @@ -106,7 +106,10 @@ type configType struct {
FindMissingExtractorAPILocation string `envconfig:"FIND_MISSING_EXTRACTOR_API_LOCATION" required:"false" default:"http://localhost:8000/api/v1"`

// Redis Recovery
RedisRecoveryRunOnly bool `envconfig:"REDIS_RECOVERY_RUN_ONLY" required:"false" default:"false"`
RedisRecoveryRunOnly bool `envconfig:"REDIS_RECOVERY_RUN_ONLY" required:"false" default:"false"`
RedisRecoveryContractsOnly bool `envconfig:"REDIS_RECOVERY_CONTRACTS_ONLY" required:"false" default:"false"`
RedisRecoveryAddresses bool `envconfig:"REDIS_RECOVERY_ADDRESSES" required:"false" default:"true"`
RedisRecoveryTokenAddresses bool `envconfig:"REDIS_RECOVERY_TOKEN_ADDRESSES" required:"false" default:"true"`

// Backfill Params
ProcessCounts bool `envconfig:"TRANSFORMER_PROCESS_COUNTS" required:"false" default:"true"`
Expand Down
4 changes: 4 additions & 0 deletions src/crud/crud_base_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (m *Crud[Model, ModelOrm]) SelectBatchOrder(
limit int,
skip int,
order string,
only_contracts bool,
) (*[]Model, error) {
db := m.db
db = db.Model(&m.Model)
Expand All @@ -110,6 +111,9 @@ func (m *Crud[Model, ModelOrm]) SelectBatchOrder(
db = db.Offset(skip)
}
db = db.Order(order)
if only_contracts {
db = db.Where("is_contract = true")
}
output := &[]Model{}
db = db.Find(output)
return output, db.Error
Expand Down
2 changes: 2 additions & 0 deletions src/routines/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var cronRoutines = []func(){
addressIsPrep,
tokenAddressCountRoutine, // Isn't used - RM?
countAddressesToRedisRoutine,
setTransactionCounts,
countAddressesToRedisRoutine,
}

func CronStart() {
Expand Down
21 changes: 13 additions & 8 deletions src/routines/routines.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ var tokenAddressRoutines = []func(t *models.TokenAddress){

func StartRecovery() {
zap.S().Warn("Init recovery...")

//Global count
setTransactionCounts()

// One shot
if config.Config.NetworkName == "mainnet" {
addressTypeRoutine()
}
countAddressesToRedisRoutine()

// Moved to cron
//Global count
//setTransactionCounts()
//countAddressesToRedisRoutine()

// By address
LoopRoutine(crud.GetCrud(models.Address{}, models.AddressORM{}), addressRoutines)
if config.Config.RedisRecoveryAddresses {
LoopRoutine(crud.GetCrud(models.Address{}, models.AddressORM{}), addressRoutines)
}
// By token address
LoopRoutine(crud.GetCrud(models.TokenAddress{}, models.TokenAddressORM{}), tokenAddressRoutines)
if config.Config.RedisRecoveryTokenAddresses {
LoopRoutine(crud.GetCrud(models.TokenAddress{}, models.TokenAddressORM{}), tokenAddressRoutines)
}

zap.S().Info("finished recovery. exiting..")
time.Sleep(30 * time.Second)
Expand All @@ -55,7 +59,8 @@ func LoopRoutine[M any, O any](Crud *crud.Crud[M, O], routines []func(*M)) {
zap.S().Info("Starting worker on table=", Crud.TableName, " with skip=", skip, " with limit=", limit)
// Run loop until addresses have all been iterated over
for {
routineItems, err := Crud.SelectBatchOrder(limit, skip, "address")
// Grabs a set of addresses or just contracts
routineItems, err := Crud.SelectBatchOrder(limit, skip, "address", config.Config.RedisRecoveryContractsOnly)
if errors.Is(err, gorm.ErrRecordNotFound) {
zap.S().Warn("Ending address routine with error=", err.Error())
break
Expand Down

0 comments on commit b396c66

Please sign in to comment.