improve box fetch performance

by reusing a http/2 connection for all boxes to check
master
Norwin 5 years ago
parent 3547d3e0c1
commit 5abdd0debb

@ -43,7 +43,8 @@ func checkAndNotify(boxIds []string) error {
boxLocalConfig[boxID] = c boxLocalConfig[boxID] = c
} }
results, err := core.CheckBoxes(boxLocalConfig) osem := core.NewOsemClient(viper.GetString("api"))
results, err := core.CheckBoxes(boxLocalConfig, osem)
if err != nil { if err != nil {
return err return err
} }

@ -5,7 +5,6 @@ import (
"strings" "strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
) )
type BoxCheckResults map[*Box][]CheckResult type BoxCheckResults map[*Box][]CheckResult
@ -86,7 +85,7 @@ func (results BoxCheckResults) Log() {
} }
} }
func CheckBoxes(boxLocalConfs map[string]*NotifyConfig) (BoxCheckResults, error) { func CheckBoxes(boxLocalConfs map[string]*NotifyConfig, osem *OsemClient) (BoxCheckResults, error) {
log.Debug("Checking notifications for ", len(boxLocalConfs), " box(es)") log.Debug("Checking notifications for ", len(boxLocalConfs), " box(es)")
results := BoxCheckResults{} results := BoxCheckResults{}
@ -97,7 +96,7 @@ func CheckBoxes(boxLocalConfs map[string]*NotifyConfig) (BoxCheckResults, error)
boxLogger := log.WithField("boxId", boxId) boxLogger := log.WithField("boxId", boxId)
boxLogger.Info("checking box for events") boxLogger.Info("checking box for events")
box, res, err := checkBox(boxId, localConf) box, res, err := checkBox(boxId, localConf, osem)
if err != nil { if err != nil {
boxLogger.Errorf("could not run checks on box %s: %s", boxId, err) boxLogger.Errorf("could not run checks on box %s: %s", boxId, err)
errs = append(errs, err.Error()) errs = append(errs, err.Error())
@ -112,10 +111,7 @@ func CheckBoxes(boxLocalConfs map[string]*NotifyConfig) (BoxCheckResults, error)
return results, nil return results, nil
} }
func checkBox(boxId string, defaultConf *NotifyConfig) (*Box, []CheckResult, error) { func checkBox(boxId string, defaultConf *NotifyConfig, osem *OsemClient) (*Box, []CheckResult, error) {
// @FIXME: core package should be independent of viper!
osem := NewOsemClient(viper.GetString("api"))
// get box data // get box data
box, err := osem.GetBox(boxId) box, err := osem.GetBox(boxId)
if err != nil { if err != nil {

Loading…
Cancel
Save