Skip to content

Commit

Permalink
Add :autoupdate option to app config and use one top-level supervisor.
Browse files Browse the repository at this point in the history
  • Loading branch information
MSch committed Oct 5, 2015
1 parent bba5c4a commit 3a0ff44
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 56 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ For use with [Calendar](https://github.com/lau/calendar) you can still
specify tzdata ~> 0.1.7 in your mix.exs file in case you experience problems
using version ~> 0.5.2.

You can also disable the automatic downloading of new timezone databases:

```elixir
config :tzdata, :autoupdate, :disabled
```

## Documentation

Documentation can be found at http://hexdocs.pm/tzdata/
Expand Down
21 changes: 1 addition & 20 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,4 @@
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for third-
# party users, it should be done in your mix.exs file.

# Sample configuration:
#
# config :logger, :console,
# level: :info,
# format: "$date $time [$level] $metadata$message\n",
# metadata: [:user_id]

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
config :tzdata, :autoupdate, :enabled
4 changes: 2 additions & 2 deletions lib/tzdata/ets_holder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ defmodule Tzdata.EtsHolder do
require Logger
use GenServer
alias Tzdata.DataBuilder
def start_link(_) do
def start_link() do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end

def init(_) do
def init([]) do
make_sure_a_release_is_on_file
create_current_release_ets_table
{:ok, release_name} = load_release
Expand Down
14 changes: 0 additions & 14 deletions lib/tzdata/ets_holder_supervisor.ex

This file was deleted.

4 changes: 2 additions & 2 deletions lib/tzdata/release_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ defmodule Tzdata.ReleaseUpdater do
use GenServer
alias Tzdata.DataLoader

def start_link(_) do
def start_link() do
GenServer.start_link(__MODULE__, [], name: :tzdata_release_updater)
end

def init(_) do
def init([]) do
Task.async(fn -> :timer.sleep(3000); Tzdata.ReleaseUpdater.check_if_time_to_update end)
{:ok, []}
end
Expand Down
14 changes: 0 additions & 14 deletions lib/tzdata/release_updater_supervisor.ex

This file was deleted.

13 changes: 11 additions & 2 deletions lib/tzdata/tzdata_app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ defmodule Tzdata.App do
use Application

def start(_type, _args) do
Tzdata.EtsHolderSupervisor.start_link
Tzdata.ReleaseUpdaterSupervisor.start_link
import Supervisor.Spec

children = [
worker(Tzdata.EtsHolder, [])
]
children = case Application.fetch_env(:tzdata, :autoupdate) do
{:ok, :enabled} -> children ++ [worker(Tzdata.ReleaseUpdater, [])]
{:ok, :disabled} -> children
end

{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
end
end
10 changes: 8 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ defmodule Tzdata.Mixfile do
end

def application do
[applications: [:hackney, :logger],
mod: {Tzdata.App, []}
[
applications: [:hackney, :logger],
env: env,
mod: {Tzdata.App, []}
]
end

Expand All @@ -25,6 +27,10 @@ defmodule Tzdata.Mixfile do
]
end

defp env do
[autoupdate: true]
end

defp description do
"""
Tzdata is a parser and library for the tz database.
Expand Down

0 comments on commit 3a0ff44

Please sign in to comment.