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) readiness.RegisterComponent(common.ReadinessAlgorandSyncing)
chainObsvReqC[vaa.ChainIDAlgorand] = make(chan *gossipv1.ObservationRequest, observationRequestBufferSize) chainObsvReqC[vaa.ChainIDAlgorand] = make(chan *gossipv1.ObservationRequest, observationRequestBufferSize)
if err := supervisor.Run(ctx, "algorandwatch", 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 return err
} }
} }

View File

@ -38,18 +38,8 @@ func RunWithScissors(ctx context.Context, errC chan error, name string, runnable
}() }()
} }
type (
Scissors struct {
runnable supervisor.Runnable
}
)
func WrapWithScissors(runnable supervisor.Runnable) supervisor.Runnable { func WrapWithScissors(runnable supervisor.Runnable) supervisor.Runnable {
s := Scissors{runnable: runnable} return func(ctx context.Context) (result error) {
return s.Run
}
func (e *Scissors) Run(ctx context.Context) (result error) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
switch x := r.(type) { switch x := r.(type) {
@ -62,5 +52,6 @@ func (e *Scissors) Run(ctx context.Context) (result error) {
} }
}() }()
return e.runnable(ctx) return runnable(ctx)
}
} }