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
Improved generated config/application.cr commented code to work once uncommented. #429
Conversation
…, int32) etc. ENV vars are all strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question about whether or not we should provide hard-coded defaults for any missing ENV variables.
# | ||
# | ||
# Process Count: This will enable Amber to be used in cluster mode, | ||
# spinning an instance for each number of process specified here. | ||
# Rule of thumb, always leave at least 1 core available for system processes/resources. | ||
# | ||
# settings.port = (ENV["PORT"] ||= 80).to_i | ||
# settings.process_count = ENV["PROCESS_COUNT"].to_i if ENV["PROCESS_COUNT"]? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a hardcoded fallback here?
settings.process_count = ENV["PROCESS_COUNT"]? ? ENV["PROCESS_COUNT"].to_i : 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have process_count = 1
here
Notice ]?
, so returns nil
if not found and setting attribute is not assigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. There is already a fall back for all of them. They just weren't being used if the environment var was missing.
# | ||
# PORT: This is the port that you're application will run on. Examples would be (80, 443, 3000, 8080) | ||
# | ||
settings.port = ENV["PORT"].to_i if ENV["PORT"]? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here, should there be a default, or do we want it to fail loudly if that ENV variable isn't there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already using port = 3000
here
:ditto:
Do we want it to fail loudly if that ENV variable isn't there?
I will not fail because is checking PORT availability first if ENV["PORT"]?
It's pointless to have a default if we're going to overwrite it with a non existent environment var. I strongly feel that we should follow the same pattern that all the other Frameworks we have used for the last 10 years follow. Use the default unless the environment variable exists. |
Description of the Change
Benefits
Within Rails and Phoenix every ENV override has default values that are used instead if they're not set.
For example: If a PORT isn't set it goes to 3000, if an RAILS_ENV isn't set it goes to development, if DATABASE_URL isn't set it uses settings from database.yml.
I don't think that it's clear to users that uncommenting the code in application.cr will work differently.
For instance if settings port is 3000, ENV["PORT"] should only override that if ENV["PORT"] has a value. Otherwise we just end up with a project that doesn't work.
settings.port = ENV["PORT"]
will fail in too many situations that aren't expected by people coming from rails/laravel, pheonix, hanami.Instead it should be
settings.port = ENV["PORT"].to_i if ENV["PORT"]?
.Otherwise we just end up with a weird situation were we load values in and immediately overwrite them with values that may not even exist.
We now end up with example code that will work out of the box, which will result in fewer complaints.