node: Simplify WrapWithScissors and make AlgorandWatcher use it

This commit is contained in:
Josh Siegel 2023-01-04 18:39:52 +00:00 committed by jumpsiegel
parent 72e3a103b8
commit 04ed27cb3f
2 changed files with 14 additions and 23 deletions

View File

@ -1127,7 +1127,7 @@ func runNode(cmd *cobra.Command, args []string) {
readiness.RegisterComponent(common.ReadinessAlgorandSyncing)
chainObsvReqC[vaa.ChainIDAlgorand] = make(chan *gossipv1.ObservationRequest, observationRequestBufferSize)
if err := supervisor.Run(ctx, "algorandwatch",
algorand.NewWatcher(*algorandIndexerRPC, *algorandIndexerToken, *algorandAlgodRPC, *algorandAlgodToken, *algorandAppID, lockC, chainObsvReqC[vaa.ChainIDAlgorand]).Run); err != nil {
common.WrapWithScissors(algorand.NewWatcher(*algorandIndexerRPC, *algorandIndexerToken, *algorandAlgodRPC, *algorandAlgodToken, *algorandAppID, lockC, chainObsvReqC[vaa.ChainIDAlgorand]).Run)); err != nil {
return err
}
}

View File

@ -38,29 +38,20 @@ func RunWithScissors(ctx context.Context, errC chan error, name string, runnable
}()
}
type (
Scissors struct {
runnable supervisor.Runnable
}
)
func WrapWithScissors(runnable supervisor.Runnable) supervisor.Runnable {
s := Scissors{runnable: runnable}
return s.Run
}
func (e *Scissors) Run(ctx context.Context) (result error) {
defer func() {
if r := recover(); r != nil {
switch x := r.(type) {
case error:
result = x
default:
result = fmt.Errorf("%v", x)
return func(ctx context.Context) (result error) {
defer func() {
if r := recover(); r != nil {
switch x := r.(type) {
case error:
result = x
default:
result = fmt.Errorf("%v", x)
}
ScissorsErrors.Inc()
}
ScissorsErrors.Inc()
}
}()
}()
return e.runnable(ctx)
return runnable(ctx)
}
}