Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support LifeCycleCallback #4918

Merged
merged 1 commit into from Apr 29, 2022
Merged

support LifeCycleCallback #4918

merged 1 commit into from Apr 29, 2022

Conversation

robberphex
Copy link
Contributor

@robberphex robberphex commented Apr 21, 2022

  • Run graceful mode by default.
    Go's net.http.Server cannot process in-transit requests when the server is shuting down, so graceful is set to the default Server implementation. net.http.Server is used only if the user manually turn off (graceful=false).
  • Support GetAllControllerInfo. GetAllControllerInfo can be used to debug and manage routing information conveniently in debugging and other extension mechanisms.
  • Support LifeCycleCallback. Adding 'AfterStart' and 'BeforeShutdown' extension points in the Beego framework lifecycle to provide more extensibility.

  • 默认使用graceful模式。Go的net.http.Server 在下线流量时会导致无法处理在途请求,所以将graceful设置为默认的Server实现。如果用户手动关闭的话(graceful=false),才使用net.http.Server
  • 支持路由信息内省GetAllControllerInfo)。在调试或者其他扩展机制中,路由信息内省可以很方便的调试、管理路由信息。
    比如在应用启动时,列出所有的route信息,有助于业务开发者查看路由是否生效。
  • 支持生命周期回调。在beego框架生命周期中,增加AfterStartBeforeShutdown扩展点,能够提供更多的扩展性。
    比如在应用就绪后,将应用注册到consul等注册中心。

@robberphex robberphex changed the title add callback support LifeCycleCallback Apr 24, 2022
@jianzhiyao
Copy link
Member

DeepSource test cases can not pass. Pls take a look!
@robberphex

@flycash
Copy link
Collaborator

flycash commented Apr 25, 2022

why we need this feature? can you provide some scenarios?

server/web/config.go Outdated Show resolved Hide resolved
server/web/router_test.go Show resolved Hide resolved
server/web/server.go Outdated Show resolved Hide resolved
server/web/server.go Show resolved Hide resolved
@@ -76,6 +77,12 @@ func NewHttpServerWithCfg(cfg *Config) *HttpServer {
// MiddleWare function for http.Handler
type MiddleWare func(http.Handler) http.Handler

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is no any implement of LifeCycleCallback ?

@jianzhiyao
Copy link
Member

lgtm

@sonarcloud
Copy link

sonarcloud bot commented Apr 29, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
3.3% 3.3% Duplication

@jianzhiyao jianzhiyao merged commit 69c17fa into beego:develop Apr 29, 2022
robberphex added a commit to robberphex/example-beego-opensergo that referenced this pull request Apr 29, 2022
robberphex added a commit to robberphex/example-beego-opensergo that referenced this pull request Apr 29, 2022
robberphex added a commit to robberphex/example-beego-opensergo that referenced this pull request Apr 29, 2022
@xuing
Copy link
Contributor

xuing commented May 30, 2022

这个合并,导致我无法开启graceful模式,开启后执行到ServeWithListener时,就不继续向下执行了..请问大家居然都没有遇到类似问题吗?

@robberphex
Copy link
Contributor Author

有最小可复现的例子吗?我来看看。

@xuing
Copy link
Contributor

xuing commented May 31, 2022

有最小可复现的例子吗?我来看看。

https://github.com/xuing/beego_demo01
#4968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants