Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Kilkelly committed Mar 30, 2018
1 parent 7a354bf commit cae35f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
28 changes: 27 additions & 1 deletion lib/hammer/application.ex
@@ -1,13 +1,39 @@
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
of separate, named backends. Examples:
`{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
Expand Down
29 changes: 7 additions & 22 deletions 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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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},
Expand Down

0 comments on commit cae35f3

Please sign in to comment.