trot icon indicating copy to clipboard operation
trot copied to clipboard

Don't use Application.gev_env

Open mtwilliams opened this issue 9 years ago • 2 comments

I need to run multiple Trot instances, and global configuration stamps on those dreams. Manually building a supervision tree works as a quick hack, but I still have to contend with pre_routing and post_routing being global.

Instead, configuration should be pulled via options passed into init/1.

mtwilliams avatar Mar 22 '16 21:03 mtwilliams

So there are two places that Application.get_env/3 is used, and I think its worth making a distinction between them. One is in the router, which it sounds like is what you're having trouble working around. I'm totally fine with replacing that with init/1 options.

The second place is in the supervisor and used for things like what port to listen on. I think that makes sense to have as env settings, but I'd be interested in hearing about your use case if you're asking to configure those settings via passed args as well.

hexedpackets avatar Mar 29 '16 01:03 hexedpackets

With regards to the latter, I need to run both an unsecured and secured (http and https) endpoints. Separating them into distinct applications (under an umbrella) just doesn't make sense (most of the code is shared, maintaining two separate applications is needlessly complex, and so on).

The thing is, you can have both. You just have to move the Application.get_env specific code into Trot.start/2, wherein you translate the environment settings into options that are passed to Trot.Supervisor.init/1 (via Trot.Supervisor.start_link.)

I can submit a pull request that does the aforementioned (and by nature, it will not break backwards compatibility).

mtwilliams avatar Mar 31 '16 05:03 mtwilliams