-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add preamble service that runs closure before running service #200
base: main
Are you sure you want to change the base?
Conversation
Hi @adam-fowler, do you use this pattern because the contents of the preamble closure need to run inside a ServiceGroup, for example because they use graceful shutdown? I assume there's a reason this wouldn't work for you? try await performDatabaseMigrations()
let serviceGroup = ServiceGroup(
services: [
webserver
],
logger: logger
) |
I think we can model this a bit differently to support |
The database is also a service. So it needs to be running as well. |
Can you give us a code example to show what you mean. |
🤦♂️ I completely missed that And |
That's because I edited it
The way I see it databaseService comes from a library eg PostgresClient from PostgresNIO and the migrations are specific to the application, so they are two separate things |
If the database should never be used until migrations have run, an alternative spelling would be for the |
This wouldn't work as all Services start at the same time. |
Right, them starting at the same time is why I suggested moving the "postamble" closure into the PostgresClient (in the wrapper might not be enough). It'd need some way to keep the client marked as not-yet-running (to avoid processing incoming requests yet), but also provide a handle to make requests only to the "postamble" closure, to be able to run startup steps without racing with other requests. But maybe that's unnecessarily complicated. |
In general, I think we have three approaches for the problem at hand:
I understand the pragmatism behind your proposed PR here but I'm not sure this is the overall approach that we should recommend. I would like us to think through the other design spaces as well before adding the |
I find I am writing this small helper service across many applications, so thought it might be of use as part of the library. Basically it is a service that runs a preamble closure before running a child service. eg
I have also extended it to take an array of services if the child service is a ServiceGroup
Struggling to find a name for the type that I'm happy with though. This was the best I could come up with.