From cae35f35d6284a567a1a52b361b9630a5eea662e Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 30 Mar 2018 17:17:00 +0100 Subject: [PATCH] Docs --- lib/hammer/application.ex | 28 +++++++++++++++++++++++++++- lib/hammer/supervisor.ex | 29 +++++++---------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/hammer/application.ex b/lib/hammer/application.ex index 9d3f3d6..82f720e 100644 --- a/lib/hammer/application.ex +++ b/lib/hammer/application.ex @@ -1,6 +1,6 @@ defmodule Hammer.Application do @moduledoc """ - Hammer application, responsible for starting the ETS backend. + Hammer application, responsible for starting the backend worker pools. Configured with the `:hammer` environment key: - `:backend`, Either a tuple of `{module, config}`, or a keyword-list @@ -8,6 +8,32 @@ defmodule Hammer.Application do `{Hammer.Backend.ETS, []}`, `[ets: {Hammer.Backend.ETS, []}, ...]` - `:suppress_logs`, if set to `true`, stops all log messages from Hammer + Example of a single backend: + + config :hammer, + backend: {Hammer.Backend.ETS, [expiry: 60_000 * 60 * 2]} + + Example of config for multiple-backends: + + config :hammer, + backend: [ + ets: { + Hammer.Backend.ETS, + [ + ets_table_name: :hammer_backend_ets_buckets, + expiry_ms: 60_000 * 60 * 2, + cleanup_interval_ms: 60_000 * 2 + ] + }, + redis: { + Hammer.Backend.Redis, + [ + expiry_ms: 60_000 * 60 * 2, + redix_config: [host: "localhost", port: 6379] + ] + } + ] + """ use Application diff --git a/lib/hammer/supervisor.ex b/lib/hammer/supervisor.ex index 4c48958..da06e1d 100644 --- a/lib/hammer/supervisor.ex +++ b/lib/hammer/supervisor.ex @@ -1,27 +1,9 @@ defmodule Hammer.Supervisor do @moduledoc """ - Top-level Supervisor for the Hammer application - - Example of config for multiple-backends: - - config :hammer, - backend: [ - ets: { - Hammer.Backend.ETS, - [ - ets_table_name: :hammer_backend_ets_buckets, - expiry_ms: 60_000 * 60 * 2, - cleanup_interval_ms: 60_000 * 2 - ] - }, - redis: { - Hammer.Backend.Redis, - [ - expiry_ms: 60_000 * 60 * 2, - redix_config: [host: "localhost", port: 6379] - ] - } - ] + Top-level Supervisor for the Hammer application. + Starts a set of poolboy pools based on provided configuration, + which are latter called to by the `Hammer` module. + See the Application module for configuration examples. """ use Supervisor @@ -30,6 +12,7 @@ defmodule Hammer.Supervisor do Supervisor.start_link(__MODULE__, config, opts) end + # Single backend def init(config) when is_tuple(config) do children = [ to_pool_spec(:hammer_backend_single_pool, config) @@ -38,6 +21,7 @@ defmodule Hammer.Supervisor do Supervisor.init(children, strategy: :one_for_one) end + # Multiple backends def init(config) when is_list(config) do children = config @@ -46,6 +30,7 @@ defmodule Hammer.Supervisor do Supervisor.init(children, strategy: :one_for_one) end + # Private helpers defp to_pool_spec(name, {mod, args}) do opts = [ name: {:local, name},