Skip to content
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

Merged
merged 5 commits into from
Jul 23, 2019
Merged

Add ENV vars to manage updating period #2401

merged 5 commits into from
Jul 23, 2019

Conversation

saneery
Copy link
Contributor

@saneery saneery commented Jul 22, 2019

#2344 #2343

Motivation

Added two ENV vars to manage updating period of average block time and market history cache

  • AVERAGE_BLOCK_CACHE_PERIOD in seconds
  • MARKET_HISTORY_CACHE_PERIOD in seconds

@coveralls
Copy link

coveralls commented Jul 22, 2019

@saneery saneery added the ready for review This PR is ready for reviews. label Jul 22, 2019
Copy link
Contributor

@pasqu4le pasqu4le left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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)

_ -> 60 * 60 * 6
end

config :explorer, Explorer.Market.MarketHistoryCache, ttl: :timer.seconds(market_history_cache_ttl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same point as above

@saneery
Copy link
Contributor Author

saneery commented Jul 22, 2019

@pasqu4le updated


config :explorer, Explorer.Counters.AverageBlockTime,
enabled: true,
period: :timer.seconds(average_block_period)
Copy link
Contributor

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.

Copy link
Contributor Author

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 😬

Copy link
Member

@vbaranov vbaranov left a 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

@saneery
Copy link
Contributor Author

saneery commented Jul 23, 2019

And still I would suggest renaming in order of naming generalization of cache parameters:

yes, I think you're right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review This PR is ready for reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants