rails / spring

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

Add Spring.reset_on_env #704

Closed gmcgibbon closed 11 months ago

gmcgibbon commented 1 year ago

Closes https://github.com/rails/spring/issues/420

Spring needs to restart when certain important environment variables change (eg. DATABASE_URL). Without this, comamnds connect to a stale application instance that has been booted with incorrect config.

Configuration must be set in config/spring_client.rb:

Spring.reset_on_env << "SOME_ENV"

So it can be used like this:

> export SOME_ENV=1 # exports env
> bin/rails runner "" # start server
> SOME_ENV=2 bin/rails runner "" # restarts server