From cebec7b15446eea94544a1e2a6bfe8deaa9c3ee2 Mon Sep 17 00:00:00 2001 From: eamon Date: Thu, 28 May 2020 12:29:45 +0800 Subject: [PATCH] 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)