Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion indexer/aggregates_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type AggregatesCalculator struct {
updateAggregatesJob *jobs.UpdateAggregatesJob
}

const aggregateScoreUpdateInterval = 10 * time.Minute

func NewAggregatesCalculator(config config.Config) *AggregatesCalculator {
logger := logging.NewZapLogger(config).Named("AggregatesCalculator")
readPool, err := dbv1.NewDBPools([]string{config.ReadDbUrl}, logger, config.Env, config.ZapLevel)
Expand All @@ -46,7 +48,8 @@ func NewAggregatesCalculator(config config.Config) *AggregatesCalculator {
func (a *AggregatesCalculator) Start(ctx context.Context) error {
a.logger.Info("Starting aggregates calculator")
go logging.SyncOnTicks(ctx, a.logger, time.Second*10)
// This job runs in a continous loop until the context is cancelled.
// This job scans all scoreable users. Keep the cadence bounded so a
// completed full pass does not immediately start another full pass.
for {
select {
case <-ctx.Done():
Expand All @@ -55,6 +58,20 @@ func (a *AggregatesCalculator) Start(ctx context.Context) error {
default:
a.updateAggregatesJob.Run(ctx)
}

timer := time.NewTimer(aggregateScoreUpdateInterval)
select {
case <-ctx.Done():
if !timer.Stop() {
select {
case <-timer.C:
default:
}
}
a.logger.Info("Shutting down aggregates calculator")
return ctx.Err()
case <-timer.C:
}
}
}

Expand Down
Loading