Skip to content

Conversation

@gmcgibbon
Copy link
Member

@gmcgibbon gmcgibbon commented Nov 22, 2023

Similar to #704, but spawns a new app instead of restarting the app process.

Currently, the only way Spring can create multiple applications for a given environment variable value is by changing the SPRING_APPLICATION_ID. This has the tradeoff of not being visible in bin/spring status calls, and being treated as a separate application, when it actually isn't. You might want to run an application with and without certain features enabled in the same rails env, and with this patch you can do that and have Spring treat these as the same app.

Configuration must be set in config/spring_client.rb:

Spring.spawn_on_env << "SOME_ENV"
> SOME_ENV=1 bin/rails runner "" # start server
> SOME_ENV=2 bin/rails runner "" # starts another server
> bin/spring status
Spring is running:

<pid> spring server | app | started 28 secs ago
<pid> spring app    | app | started 28 secs ago | development mode
<pid> spring app    | app | started 28 secs ago | development mode | RAILS_CONTEXT=essentials

@byroot
Copy link
Member

byroot commented Nov 22, 2023

Currently, it isn't possible for Spring to create multiple applications for a given environment variable value.

I believe it's possible via ENV["SPRING_APPLICATION_ID"]

@gmcgibbon
Copy link
Member Author

gmcgibbon commented Nov 22, 2023

Ok, yes it is possible via ENV["SPRING_APPLICATION_ID"], but it doesn't list all the applications in bin/spring status, and prefixing environment variables and manually crafting the spring app id with them isn't straightforward IMO. They are all the same application, so they should all be visible to spring calls by default.

I'll update the description.

@gmcgibbon
Copy link
Member Author

@byroot if you have time, do you have any more feedback?

Currently, the only way Spring can create multiple applications for a
given environment variable value is by changing the `SPRING_APPLICATION_ID`.
This has the tradeoff of not being visible in `bin/spring status` calls,
and being treated as a separate application, when it actually isn't. You
might want to run an application with and without certain features
enabled in the same rails env, and with this patch you can do that and
have Spring treat these as the same app.

Configuration must be set in config/spring_client.rb
@gmcgibbon
Copy link
Member Author

Hm, looks like CI is failing for a specific version for some dependency reasons. I'll look into that separately, I don't think it is related to this change.

@gmcgibbon gmcgibbon merged commit db95d8d into rails:main Dec 15, 2023
@gmcgibbon gmcgibbon deleted the spawn_on_env branch December 15, 2023 05:25
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