-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add ENV vars to manage updating period #2401
Conversation
17d240c
to
c03f6ac
Compare
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.
I think we should avoid raising and rescuing from errors in the configuration file
rescue | ||
# 30 minutes | ||
_ -> 30 * 60 | ||
end |
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.
It seems excessive to me to have a try
block here. I think it's better to use Integer.parse
to avoid raising errors.
Considering also that this variable is used only in one place (passed to a timer.seconds
) you could change the block to be:
average_block_period =
case Integer.parse(System.get_env("ADDRESS_WITH_BALANCES_UPDATE_INTERVAL", "")) do
{secs, ""} -> :timer.seconds(secs)
_ -> :timer.minutes(30)
end
This would take care of the cases where the env var is set, not set and poorly set just as well.
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.
What's bad with try
?
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.
There is nothing inherently bad with try\rescue
(maybe only a slightly worst performance, but it would not matter here), but the reason it exists is to recover from an unexpected error.
In this case you used rescue
not for something unexpected, but to use a default value after some condition are met (env var not set or wrongly set).
Also generally speaking using rescue
as part of the logic will "hide" that a truly unexpected error was raised (and where) so I'd say it is best practice to avoid doing so (even tho it's hardly the case here because not much is going on)
apps/explorer/config/config.exs
Outdated
_ -> 60 * 60 * 6 | ||
end | ||
|
||
config :explorer, Explorer.Market.MarketHistoryCache, ttl: :timer.seconds(market_history_cache_ttl) |
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 point as above
@pasqu4le updated |
apps/explorer/config/config.exs
Outdated
|
||
config :explorer, Explorer.Counters.AverageBlockTime, | ||
enabled: true, | ||
period: :timer.seconds(average_block_period) |
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.
@saneery I see you have updated the parsing, but now :timer.seconds
here (and for market_history_cache_ttl
as well) should be removed, because it is already handled on the variable creation.
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.
Oh, I forgot about them 😬
c32d2d5
to
c2dec2a
Compare
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.
@saneery
And still I would suggest renaming in order of naming generalization of cache parameters:
AVERAGE_BLOCK_PERIOD
-> AVERAGE_BLOCK_CACHE_PERIOD
MARKET_HISTORY_CACHE_TTL
-> MARKET_HISTORY_CACHE_PERIOD
yes, I think you're right |
a48fb1e
to
e93b71c
Compare
#2344 #2343
Motivation
Added two ENV vars to manage updating period of average block time and market history cache
AVERAGE_BLOCK_CACHE_PERIOD
in secondsMARKET_HISTORY_CACHE_PERIOD
in seconds