|
|
@ -55,8 +55,7 @@ defmodule Explorer.History.Process do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp schedule_next_compilation do |
|
|
|
defp schedule_next_compilation do |
|
|
|
delay = config_or_default(:history_fetch_interval, :timer.minutes(60)) |
|
|
|
Process.send_after(self(), {:compile_historical_records, 2}, calculate_delay_until_next_midnight()) |
|
|
|
Process.send_after(self(), {:compile_historical_records, 2}, delay) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@spec failed_compilation(non_neg_integer(), module(), non_neg_integer()) :: any() |
|
|
|
@spec failed_compilation(non_neg_integer(), module(), non_neg_integer()) :: any() |
|
|
@ -108,4 +107,14 @@ defmodule Explorer.History.Process do |
|
|
|
multiplier = Enum.reduce(2..failed_attempts, 1, fn _, acc -> 2 * acc end) |
|
|
|
multiplier = Enum.reduce(2..failed_attempts, 1, fn _, acc -> 2 * acc end) |
|
|
|
multiplier * base_backoff() |
|
|
|
multiplier * base_backoff() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp calculate_delay_until_next_midnight do |
|
|
|
|
|
|
|
now = DateTime.utc_now() |
|
|
|
|
|
|
|
# was added for testing possibility |
|
|
|
|
|
|
|
time_to_fetch_at = config_or_default(:time_to_fetch_at, Time.new!(0, 0, 0, 0)) |
|
|
|
|
|
|
|
days_to_add = config_or_default(:days_to_add, 1) |
|
|
|
|
|
|
|
tomorrow = DateTime.new!(Date.add(Date.utc_today(), days_to_add), time_to_fetch_at, now.time_zone) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime.diff(tomorrow, now, :millisecond) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|