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

Refactor fx Start/Stop usage #4248

Merged
merged 6 commits into from May 1, 2023
Merged

Refactor fx Start/Stop usage #4248

merged 6 commits into from May 1, 2023

Conversation

dnr
Copy link
Member

@dnr dnr commented Apr 27, 2023

What changed?

  • Move blocking start outside of fx lifecycle hook
  • Propagate outer app Start/Stop context to inner Apps (currently just Background)
  • Refactor StopService into proper method
  • Other small cleanups

This leaves the shutdown timeout in the inner Apps: if we set a single timeout on the outer one, fx itself might abort shutdown and not give the inner ones time to finish, so I think it's more robust this way.

Why?
Simplify and correct usage of fx

How did you test it?
Local testing, integration tests

Potential risks

Is hotfix candidate?

@dnr dnr requested a review from a team as a code owner April 27, 2023 23:54
Copy link
Contributor

@MichaelSnowden MichaelSnowden left a comment

Choose a reason for hiding this comment

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

This definitely looks correct to me at a glance, but I think the unrelated parts should be split into separate PRs, to make it harder to miss any issues

temporal/fx.go Outdated
Logger log.Logger
ClientFactoryProvider client.FactoryProvider
DynamicConfigClient dynamicconfig.Client
DynamicConfigCollection *dynamicconfig.Collection
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is a separate change from Start/Stop, I think it should be its own PR

Copy link
Member Author

Choose a reason for hiding this comment

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

alright

temporal/fx.go Outdated
Comment on lines 152 to 153
fx.Populate(&s.blockingStart),
fx.Populate(&s.logger),
Copy link
Contributor

Choose a reason for hiding this comment

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

The ServerFx object is provided by the NewServerFxImpl provider. We can just inject the blockingStart and logger fields there.

Copy link
Member Author

Choose a reason for hiding this comment

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

The ServerFx object is constructed right here. NewServerFxImpl provides a *ServerImpl, not a ServerFx (the names in here are a twisty maze…)

*ServerFx implements Server, but *ServerImpl doesn't. It previously did, but the point was adding contexts, so it can't anymore.

I can rename stuff to make it less confusing but tbh I'm not even sure where to start 😅 Maybe renaming NewServerFxImpl to NewServerImpl? Or ServerImpl to …? And then ServerFx to ServerImpl?

Copy link
Contributor

Choose a reason for hiding this comment

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

...let's figure this out later lol

temporal/fx.go Outdated
}

ServerFx struct {
app *fx.App
app *fx.App
blockingStart blockingStartParams
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think startupSynchronizationMode with synchronizationModeParams is a bit better

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, that's a nice name

Comment on lines -552 to -557
return ServicesGroupOut{
Services: &ServicesMetadata{
App: fx.New(fx.NopLogger),
ServiceName: serviceName,
ServiceStopFn: func() {},
},
}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great change, but can we move it to a separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I split out the Collection one (already in a separate commit) but I'd rather not spend time on splitting the rest, they're fairly intertwined

@dnr dnr merged commit 661d6d4 into temporalio:master May 1, 2023
10 checks passed
samanbarghi pushed a commit to samanbarghi/temporal that referenced this pull request May 2, 2023
samanbarghi pushed a commit to samanbarghi/temporal that referenced this pull request May 5, 2023
wxing1292 added a commit that referenced this pull request May 11, 2023
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

2 participants