@@ -11,13 +11,16 @@ import (
1111 "github.com/gobitfly/beaconchain/pkg/commons/utils"
1212 "github.com/gobitfly/beaconchain/pkg/consapi"
1313 "github.com/gobitfly/beaconchain/pkg/consapi/types"
14+ "github.com/gobitfly/beaconchain/pkg/monitoring/constants"
15+ "github.com/gobitfly/beaconchain/pkg/monitoring/services"
1416 "github.com/pkg/errors"
1517 "golang.org/x/sync/errgroup"
1618)
1719
1820type ModuleInterface interface {
1921 Init () error
2022 GetName () string // Used for logging
23+ GetMonitoringEventId () constants.Event
2124
2225 OnHead (* types.StandardEventHeadResponse ) error // !Do not block in this functions for an extended period of time!
2326
@@ -63,7 +66,6 @@ func StartAll(context ModuleContext, modules []ModuleInterface, justV2 bool) {
6366 log .Error (err , "beacon-node seems to be unavailable" , 0 )
6467 time .Sleep (time .Second * 10 )
6568 }
66-
6769 // start subscription modules
6870 startSubscriptionModules (& context , modules )
6971}
@@ -146,15 +148,20 @@ func notifyAllModules(goPool *errgroup.Group, modules []ModuleInterface, f func(
146148 for _ , module := range modules {
147149 module := module
148150 goPool .Go (func () error {
151+ start := time .Now ()
152+ r := services .NewStatusReport (module .GetMonitoringEventId (), constants .Default , constants .Default )
153+ r (constants .Running , nil )
149154 err := f (module )
150155 if err != nil {
151156 log .Error (err , fmt .Sprintf ("error in module %s" , module .GetName ()), 0 )
157+ r (constants .Failure , map [string ]string {"error" : err .Error ()})
158+ return nil // return never gets caught anywhere? lets not risk a memory leak and instead return nil
152159 }
160+ r (constants .Success , map [string ]string {"took_raw" : fmt .Sprintf ("%v" , time .Since (start ).Milliseconds ())})
153161 return nil
154162 })
155163 }
156164}
157-
158165func GetModuleContext () (ModuleContext , error ) {
159166 cl := consapi .NewClient ("http://" + utils .Config .Indexer .Node .Host + ":" + utils .Config .Indexer .Node .Port )
160167
0 commit comments