Skip to content

Commit

Permalink
fix: add timer to normalize requests (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasteph authored Oct 21, 2024
1 parent f64f4f1 commit 855f9ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
31 changes: 15 additions & 16 deletions queen.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,22 @@ func (q *Queen) freePort(port uint16) {

func (q *Queen) Run(ctx context.Context) {
go q.consumeAntsLogs(ctx)
go q.normalizeRequests(ctx)

t := time.NewTicker(CRAWL_INTERVAL)
crawlTime := time.NewTicker(CRAWL_INTERVAL)
defer crawlTime.Stop()

normalizationTime := time.NewTicker(NORMALIZATION_INTERVAL)
defer normalizationTime.Stop()

q.routine(ctx)

for {
select {
case <-t.C:
case <-crawlTime.C:
q.routine(ctx)
case <-normalizationTime.C:
go q.normalizeRequests(ctx)
// time.Sleep(10 * time.Second)
case <-ctx.Done():
q.persistLiveAntsKeys()
return
Expand Down Expand Up @@ -271,19 +278,11 @@ func (q *Queen) normalizeRequests(ctx context.Context) {

logger.Info("Starting continuous normalization...")

for {
select {
case <-nctx.Done():
logger.Info("Normalization context canceled, stopping normalization loop.")
return
default:
err := db.NormalizeRequests(nctx, q.dbc.Handler, q.dbc)
if err != nil {
logger.Errorf("Error during normalization: %w", err)
} else {
logger.Info("Normalization completed for current batch.")
}
}
err := db.NormalizeRequests(nctx, q.dbc.Handler, q.dbc)
if err != nil {
logger.Errorf("Error during normalization: %w", err)
} else {
logger.Info("Normalization completed for current batch.")
}
}

Expand Down
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
)

const (
CRAWL_INTERVAL = 30 * time.Minute

BUCKET_SIZE = 20
CRAWL_INTERVAL = 30 * time.Minute
NORMALIZATION_INTERVAL = 60 * time.Second
BUCKET_SIZE = 20
)

func PeeridToKadid(pid peer.ID) bit256.Key {
Expand Down

0 comments on commit 855f9ff

Please sign in to comment.