node: Simplify WrapWithScissors and make AlgorandWatcher use it
This commit is contained in:
parent
72e3a103b8
commit
04ed27cb3f
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue