From dedeaa52a1728b384a6b982d40b791856e784aec Mon Sep 17 00:00:00 2001 From: Edward Date: Tue, 26 May 2020 18:05:19 +0800 Subject: [PATCH 1/4] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4023528..69e4fe4 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ go test ./... ## 弹性模式 Resiliency Patterns -+ [ ] [WIP][熔断模式(circuit breaker](./resiliency/06_circuit_breaker) -+ [x] [限流模式(rate limiting))](./resiliency/07_rate_limiting) ++ [x] [熔断模式(circuit breaker](./resiliency/06_circuit_breaker) ++ [x] [限流模式(rate limiting)](./resiliency/07_rate_limiting) + [ ] [WIP][重试模式(retrier)](./resiliency/15_retrier) + [ ] [WIP][最后期限模式(deadline)](./resiliency/14_deadline) From 7e819e997dbc4920b3303529ae4a5f6d8f0b9c16 Mon Sep 17 00:00:00 2001 From: Edward Date: Tue, 26 May 2020 18:06:15 +0800 Subject: [PATCH 2/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69e4fe4..8110a26 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ go test ./... ## 弹性模式 Resiliency Patterns -+ [x] [熔断模式(circuit breaker](./resiliency/06_circuit_breaker) ++ [x] [熔断模式(circuit breaker)](./resiliency/06_circuit_breaker) + [x] [限流模式(rate limiting)](./resiliency/07_rate_limiting) + [ ] [WIP][重试模式(retrier)](./resiliency/15_retrier) + [ ] [WIP][最后期限模式(deadline)](./resiliency/14_deadline) From ec6a2cf03787b53ea58dd910d3f1fa4d635c713b Mon Sep 17 00:00:00 2001 From: eamon Date: Wed, 27 May 2020 11:16:03 +0800 Subject: [PATCH 3/4] update settings --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 462a89a..4ec7b65 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "parameter":"#4c70e7", } }, + "extensions.showRecommendationsOnlyOnDemand": true, "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, "extensions.ignoreRecommendations": true, From cebec7b15446eea94544a1e2a6bfe8deaa9c3ee2 Mon Sep 17 00:00:00 2001 From: eamon Date: Thu, 28 May 2020 12:29:45 +0800 Subject: [PATCH 4/4] add settings --- .vscode/settings.json | 9 +++--- .../06_circuit_breaker/circuit_breaker_adv.go | 29 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4ec7b65..6312ae5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "window.autoDetectColorScheme": false, "editor.tabSize": 2, "editor.semanticTokenColorCustomizations":{ "enabled": true, // enable semantic highlighting for all themes @@ -22,15 +23,15 @@ "activityBar.inactiveForeground": "#15202b99", "activityBarBadge.background": "#cfd3ef", "activityBarBadge.foreground": "#15202b", - "titleBar.activeBackground": "#5e7959", - "titleBar.inactiveBackground": "#5e795999", - "titleBar.activeForeground": "#e7e7e7", - "titleBar.inactiveForeground": "#e7e7e799", "statusBarItem.hoverBackground": "#759570", "statusBar.foreground": "#e7e7e7", "activityBar.activeBackground": "#759570", "statusBar.background": "#5e7959", "statusBar.border": "#5e7959", + "titleBar.activeBackground": "#5e7959", + "titleBar.inactiveBackground": "#5e795999", + "titleBar.activeForeground": "#e7e7e7", + "titleBar.inactiveForeground": "#e7e7e799", "titleBar.border": "#5e7959" }, "go.languageServerFlags": [], diff --git a/resiliency/06_circuit_breaker/circuit_breaker_adv.go b/resiliency/06_circuit_breaker/circuit_breaker_adv.go index 15e9acd..ed01163 100644 --- a/resiliency/06_circuit_breaker/circuit_breaker_adv.go +++ b/resiliency/06_circuit_breaker/circuit_breaker_adv.go @@ -82,33 +82,32 @@ func (rb *RequestBreaker) Do(work func(ctx context.Context) (interface{}, error) //before fmt.Println("before do : request:", rb.cnter.Total()) - rb.mutex.Lock() - //handle status of Open to HalfOpen - if rb.state == StateOpen && rb.options.Expiry.Before(time.Now()) { - rb.state = StateHalfOpen - rb.cnter.Reset() - rb.options.OnStateChanged(rb.options.Name, StateOpen, StateHalfOpen) - } - rb.mutex.Unlock() - switch rb.state { case StateOpen: return nil, ErrTooManyRequests case StateHalfOpen: //do work from requested user - result, err := work(rb.options.Ctx) - if err != nil { - rb.cnter.Count(FailureState) + // result, err := work(rb.options.Ctx) + // if err != nil { + // rb.cnter.Count(FailureState) + // } else { + // rb.cnter.Count(SuccessState) + // return result, nil + // } - } else { - rb.cnter.Count(SuccessState) - return result, nil + if rb.options.Expiry.Before(time.Now()) { + rb.state = StateHalfOpen + rb.cnter.Reset() + rb.options.OnStateChanged(rb.options.Name, StateOpen, StateHalfOpen) } case StateClosed: } + rb.mutex.Unlock() + + //do work //do work from requested user result, err := work(rb.options.Ctx)