Skip to content

Commit

Permalink
Improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuprog committed Sep 9, 2024
1 parent 59424eb commit 12d7e2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/tz/updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ defmodule Tz.Updater do
{:ok, latest_version} ->
if latest_version != latest_version_saved &&
latest_version != PeriodsProvider.iana_version() do
Logger.info(
"New IANA time zone data version #{latest_version} available; currently using #{latest_version_saved}."
)

case update_tz_database(latest_version) do
{:ok, _dir} ->
IanaDataDir.delete_tzdata_dir(latest_version_saved)
Expand All @@ -51,6 +55,10 @@ defmodule Tz.Updater do
{:error, latest_version_saved}
end
else
Logger.info(
"Already using the latest IANA time zone data version: #{PeriodsProvider.iana_version()}."
)

{:already_latest, latest_version}
end

Expand All @@ -68,7 +76,6 @@ defmodule Tz.Updater do
case HTTP.get_http_client!().request("data.iana.org", "/time-zones/tzdb/version") do
%HTTPResponse{body: body, status_code: 200} ->
version = body |> String.trim()
Logger.info("Latest version of the IANA time zone data is #{version}")
{:ok, version}

_ ->
Expand Down
4 changes: 4 additions & 0 deletions lib/tz/watch_periodically.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ defmodule Tz.WatchPeriodically do
)

on_update_callback && on_update_callback.(latest_version)
else
Logger.info(
"Already using the latest IANA time zone data version: #{PeriodsProvider.iana_version()}."
)
end

:error ->
Expand Down
2 changes: 2 additions & 0 deletions test/updater_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ defmodule UpdaterTest do

assert {:ok, _} = start_supervised(Tz.WatchPeriodically)
assert {:error, _} = start_supervised(Tz.WatchPeriodically)

:timer.sleep(6_000)
end
end

0 comments on commit 12d7e2a

Please sign in to comment.