-
Notifications
You must be signed in to change notification settings - Fork 472
/
bizkeeper_provider_handler.go
executable file
·48 lines (39 loc) · 1.31 KB
/
bizkeeper_provider_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package handler
import (
"github.com/go-chassis/go-chassis/core/common"
"github.com/go-chassis/go-chassis/core/invocation"
"github.com/go-chassis/go-chassis/control"
"github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
)
// BizKeeperProviderHandler bizkeeper provider handler
type BizKeeperProviderHandler struct{}
// Handle handler for bizkeeper provider
func (bk *BizKeeperProviderHandler) Handle(chain *Chain, i *invocation.Invocation, cb invocation.ResponseCallBack) {
command, cmdConfig := control.DefaultPanel.GetCircuitBreaker(*i, common.Provider)
hystrix.ConfigureCommand(command, cmdConfig)
finish := make(chan *invocation.Response, 1)
err := hystrix.Do(command, func() (err error) {
chain.Next(i, func(resp *invocation.Response) error {
err = resp.Err
select {
case finish <- resp:
default:
// means hystrix error occurred
}
return err
})
return
}, GetFallbackFun(command, common.Provider, i, finish, cmdConfig.ForceFallback))
//if err is not nil, means fallback is nil, return original err
if err != nil {
writeErr(err, cb)
}
cb(<-finish)
}
// Name returns bizkeeper-provider string
func (bk *BizKeeperProviderHandler) Name() string {
return "bizkeeper-provider"
}
func newBizKeeperProviderHandler() Handler {
return &BizKeeperProviderHandler{}
}