Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make combiner queries async #254

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
22 changes: 13 additions & 9 deletions feeds/combiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/forta-network/forta-core-go/domain"
"github.com/forta-network/forta-core-go/protocol"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)

var (
Expand Down Expand Up @@ -172,19 +173,22 @@ func (cf *combinerFeed) forEachAlert(alertHandlers []cfHandler) error {
lowerBound := DefaultLookbackPeriod
upperBound := int64(0)

errGrp, ctx := errgroup.WithContext(cf.ctx)

subscriptions := cf.Subscriptions()
// Query all subscriptions and process alerts
for _, subscription := range cf.Subscriptions() {
logger = logger.WithFields(
log.Fields{
"subscriberBotId": subscription.Subscriber.BotID,
"subscribedBotId": subscription.Subscription.BotId,
for i := range subscriptions {
subscription := subscriptions[i]
errGrp.Go(
aomerk marked this conversation as resolved.
Show resolved Hide resolved
func() error {
return cf.fetchAlertsAndHandle(ctx, alertHandlers, subscription, lowerBound.Milliseconds(), upperBound)
},
)
}

err := cf.fetchAlertsAndHandle(cf.ctx, alertHandlers, subscription, lowerBound.Milliseconds(), upperBound)
if err != nil {
logger.WithError(err).Warn("failed to fetch alerts and handle")
}
err := errGrp.Wait()
if err != nil{
logger.WithError(err).Warn("failed to process combiner subscriptions")
}

// Save alert cache to persistent file, if configured
Expand Down