diff options
| author | zhangjie <iamkadisi@163.com> | 2019-11-18 14:30:02 +0800 |
|---|---|---|
| committer | zhangjie <iamkadisi@163.com> | 2019-11-18 21:05:56 +0800 |
| commit | 5cbd5652c4639278e3e397788fefbfe3f2c8035e (patch) | |
| tree | 9b4f4e8ffae4d9116cfb474997fb1671a2e0724f /staging | |
| parent | change Context struct to BeehiveConttext. add golang ctx field to BeehiveContext (diff) | |
| download | kubeedge-5cbd5652c4639278e3e397788fefbfe3f2c8035e.tar.gz | |
delete ctx, cancel field from module struct
Signed-off-by: zhangjie <iamkadisi@163.com>
Diffstat (limited to 'staging')
4 files changed, 15 insertions, 12 deletions
diff --git a/staging/src/github.com/kubeedge/beehive/pkg/core/context/context.go b/staging/src/github.com/kubeedge/beehive/pkg/core/context/context.go index 6e9710e00..480b10243 100644 --- a/staging/src/github.com/kubeedge/beehive/pkg/core/context/context.go +++ b/staging/src/github.com/kubeedge/beehive/pkg/core/context/context.go @@ -1,7 +1,7 @@ package context import ( - gcontext "context" + gocontext "context" "time" "github.com/kubeedge/beehive/pkg/core/model" @@ -28,9 +28,9 @@ type MessageContext interface { } // Context is global context object -type BeehiveContext struct { +type beehiveContext struct { moduleContext ModuleContext messageContext MessageContext - ctx gcontext.Context - cancel gcontext.CancelFunc + ctx gocontext.Context + cancel gocontext.CancelFunc } diff --git a/staging/src/github.com/kubeedge/beehive/pkg/core/context/context_factory.go b/staging/src/github.com/kubeedge/beehive/pkg/core/context/context_factory.go index 3bf2d3d2f..827261806 100644 --- a/staging/src/github.com/kubeedge/beehive/pkg/core/context/context_factory.go +++ b/staging/src/github.com/kubeedge/beehive/pkg/core/context/context_factory.go @@ -1,7 +1,7 @@ package context import ( - gcontext "context" + gocontext "context" "sync" "time" @@ -17,15 +17,15 @@ const ( var ( // singleton - context *BeehiveContext + context *beehiveContext once sync.Once ) // InitContext gets global context instance func InitContext(contextType string) { once.Do(func() { - ctx, cancel := gcontext.WithCancel(gcontext.Background()) - context = &BeehiveContext{ + ctx, cancel := gocontext.WithCancel(gocontext.Background()) + context = &beehiveContext{ ctx: ctx, cancel: cancel, } @@ -54,9 +54,13 @@ func AddModuleGroup(module, group string) { context.moduleContext.AddModuleGroup(module, group) } +// Cancel function +func Cancel() { + context.cancel() +} + // Cleanup cleans up module func Cleanup(module string) { - context.cancel() context.moduleContext.Cleanup(module) } diff --git a/staging/src/github.com/kubeedge/beehive/pkg/core/core.go b/staging/src/github.com/kubeedge/beehive/pkg/core/core.go index 2c1100d51..bae854c28 100644 --- a/staging/src/github.com/kubeedge/beehive/pkg/core/core.go +++ b/staging/src/github.com/kubeedge/beehive/pkg/core/core.go @@ -34,10 +34,10 @@ func GracefulShutdown() { case s := <-c: klog.Infof("Get os signal %v", s.String()) //Cleanup each modules + beehiveContext.Cancel() modules := GetModules() - for name, module := range modules { + for name, _ := range modules { klog.Infof("Cleanup module %v", name) - module.Cancel() beehiveContext.Cleanup(name) } } diff --git a/staging/src/github.com/kubeedge/beehive/pkg/core/module.go b/staging/src/github.com/kubeedge/beehive/pkg/core/module.go index 001f03f94..1a1e4a584 100644 --- a/staging/src/github.com/kubeedge/beehive/pkg/core/module.go +++ b/staging/src/github.com/kubeedge/beehive/pkg/core/module.go @@ -18,7 +18,6 @@ type Module interface { Name() string Group() string Start() - Cancel() } var ( |
