rails / spring

Rails application preloader
MIT License
2.81k stars 341 forks source link

Add Spring.spawn_on_env #705

Closed gmcgibbon closed 11 months ago

gmcgibbon commented 1 year ago

Similar to https://github.com/rails/spring/pull/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 commented 1 year ago

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 commented 1 year ago

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 commented 11 months ago

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

gmcgibbon commented 11 months ago

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.