Skip to content

feat(os/gapp): add unified multi-server application lifecycle#4777

Open
qinyuguang wants to merge 1 commit into
gogf:masterfrom
qinyuguang:feat/lifecycle
Open

feat(os/gapp): add unified multi-server application lifecycle#4777
qinyuguang wants to merge 1 commit into
gogf:masterfrom
qinyuguang:feat/lifecycle

Conversation

@qinyuguang

@qinyuguang qinyuguang commented May 27, 2026

Copy link
Copy Markdown
Contributor

Introduce os/gapp App to coordinate Boot, Start, Stop, and OS signal handling across multiple Server implementations, supporting graceful or forceful shutdown in one place.

  • Add contrib/scheduler/gjob worker and cron servers implementing gapp.Server
  • Add grpcx GrpcServerAdapter with managed non-blocking start
  • Add ghttp.Server.Close for forceful shutdown; harden admin restart/shutdown
  • Add gproc.StartListen for background signal handling used by gapp

Example

// main initializes and starts gRPC/HTTP servers and scheduler job servers (worker + cron).
func main() {
	ctx := gctx.GetInitCtx()

	grpcServer := grpcx.Server.New()
	controller.Register(grpcServer)

	httpServer := g.Server()
	httpServer.BindHandler("/", func(r *ghttp.Request) {
		r.Response.Write("Hello World!")
	})

	app := gapp.New(
		grpcx.NewGappServerAdapter(grpcServer),
		gapp.NewHTTPServerAdapter(httpServer),
	)
	app.Add(gjob.NewServersFromConfig(ctx, job.Handlers())...)

	app.Option(
		gapp.NewOption(func(ctx context.Context, app *gapp.App) {
			g.Log().Info(ctx, "app starting...")
		}),
	)

	if err := app.Run(ctx); err != nil {
		g.Log().Errorf(ctx, "app run failed: %+v", err)
		os.Exit(1)
	}

	g.Log().Info(ctx, "app shutdown.")
}

Introduce os/gapp App to coordinate Boot, Start, Stop, and OS signal
handling across multiple Server implementations, supporting graceful or
forceful shutdown in one place.

- Add contrib/scheduler/gjob worker and cron servers implementing gapp.Server
- Add grpcx GrpcServerAdapter with managed non-blocking start
- Add ghttp.Server.Close for forceful shutdown; harden admin restart/shutdown
- Add gproc.StartListen for background signal handling used by gapp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

2 participants