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)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
func WrapWithScissors(runnable supervisor.Runnable) supervisor.Runnable {
|
||||||
s := Scissors{runnable: runnable}
|
return func(ctx context.Context) (result error) {
|
||||||
return s.Run
|
defer func() {
|
||||||
}
|
if r := recover(); r != nil {
|
||||||
|
switch x := r.(type) {
|
||||||
func (e *Scissors) Run(ctx context.Context) (result error) {
|
case error:
|
||||||
defer func() {
|
result = x
|
||||||
if r := recover(); r != nil {
|
default:
|
||||||
switch x := r.(type) {
|
result = fmt.Errorf("%v", x)
|
||||||
case error:
|
}
|
||||||
result = x
|
ScissorsErrors.Inc()
|
||||||
default:
|
|
||||||
result = fmt.Errorf("%v", x)
|
|
||||||
}
|
}
|
||||||
ScissorsErrors.Inc()
|
}()
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return e.runnable(ctx)
|
return runnable(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue