-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor routines and add order to routine address pull
- Loading branch information
Showing
6 changed files
with
114 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package routines | ||
|
||
import ( | ||
"github.com/sudoblockio/icon-transformer/config" | ||
"go.uber.org/zap" | ||
"time" | ||
) | ||
|
||
var cronRoutines = []func(){ | ||
addressIsPrep, | ||
tokenAddressCountRoutine, // Isn't used - RM? | ||
countAddressesToRedisRoutine, | ||
} | ||
|
||
func CronStart() { | ||
|
||
zap.S().Warn("Init cron...") | ||
// Init - Jobs that run once on startup | ||
if config.Config.NetworkName == "mainnet" { | ||
addressTypeRoutine() | ||
} | ||
|
||
// Short | ||
go RoutinesCron(cronRoutines, config.Config.RoutinesSleepDuration) | ||
|
||
// Long | ||
// TODO: These were snubbed because they stress DB and should be run with something to slow them down | ||
//go AddressRoutinesCron(addressRoutines, 6*time.Hour) | ||
} | ||
|
||
// Wrapper for generic routines | ||
func RoutinesCron(routines []func(), sleepDuration time.Duration) { | ||
for { | ||
zap.S().Warn("Starting cron...") | ||
for _, r := range routines { | ||
r() | ||
} | ||
zap.S().Info("Completed routine, sleeping...") | ||
time.Sleep(sleepDuration) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package routines | ||
|
||
import ( | ||
"github.com/sudoblockio/icon-transformer/config" | ||
"github.com/sudoblockio/icon-transformer/models" | ||
"github.com/sudoblockio/icon-transformer/redis" | ||
"go.uber.org/zap" | ||
|
||
"github.com/sudoblockio/icon-transformer/crud" | ||
) | ||
|
||
func GetTokenAddressTxCounts(address *models.Address) *models.Address { | ||
|
||
// Token Transfer Count | ||
countTokenTx, err := crud.GetTokenTransferCrud().CountByAddress(address.Address) | ||
if err != nil { | ||
zap.S().Warn("Routine=InternalTxCount, Address=", address.Address, " - Error: ", err.Error()) | ||
return nil | ||
} | ||
address.TokenTransferCount = countTokenTx | ||
err = redis.GetRedisClient().SetCount( | ||
config.Config.RedisKeyPrefix+"token_transfer_count_by_token_contract_"+address.Address, | ||
countTokenTx, | ||
) | ||
if err != nil { | ||
zap.S().Warn("Routine=TokenTransfer, Address=", address.Address, " - Error: ", err.Error()) | ||
return nil | ||
} | ||
|
||
return address | ||
} | ||
|
||
func setTokenAddressTxCounts(address *models.Address) { | ||
addressNew := GetTokenAddressTxCounts(address) | ||
if address != nil { | ||
//crud.GetAddressRoutineCruds()["counts"].LoaderChannel <- addressNew | ||
err := crud.GetAddressRoutineCruds()["counts"].UpsertOne(addressNew) | ||
if err != nil { | ||
zap.S().Fatal(err.Error()) | ||
} | ||
} | ||
} |