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

Can wire help us to close server in order? #346

Open
somniapotato opened this issue Feb 23, 2022 · 3 comments
Open

Can wire help us to close server in order? #346

somniapotato opened this issue Feb 23, 2022 · 3 comments

Comments

@somniapotato
Copy link

For example, if my provider like this:
wire.Build(InitServer1, InitServer2, InitServer3)
Server3 depends on Server2
Server2 depends on Server1

When the whole server want to gracefully stop, can wire help us to close Server3 first, then Server2, Server1?
Considering that wire already know the injection sequence, I thought it could know the quit sequence too.

@MistaTwista
Copy link

MistaTwista commented Sep 22, 2022

Hey, @somniapotato did you find any workflow that works for you? There are Cleanup functions but I'm thinking is it good for graceful stop or is there some limitations

@shuqingzai
Copy link

shuqingzai commented Apr 3, 2023

This is very useful. Now when I exit gracefully, Redis or DB will be closed first (because they were created first), but other components depend on them, causing errors in other components, failing to exit gracefully, and often triggering errors or panics

@ProgrammingMuffin
Copy link

@MistaTwista I tried testing cleanup functionality and you still have to manually call the cleanups. I think what @somniapotato is trying to say here is to automatically call the cleanups.

Correct me if I am wrong here @MistaTwista

This is what I tried.

package main

import (
	"fmt"

	"github.com/google/wire"
)

type Foo struct {
	Name string
}

func NewProvider() (Foo, func()) {
	return Foo{Name: "hello!"}, func() {
		fmt.Println("running cleanup for Foo!")
	}
}

func main() {
	foo, cleanup := InitializeEvent()
	cleanup()
	fmt.Println("The name is: ", foo.Name)
}

func InitializeEvent() (Foo, func()) {
	wire.Build(NewProvider)
	return Foo{}, func() {}
}

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

No branches or pull requests

4 participants