Skip to content

Commit

Permalink
Merge pull request #1 from Recruitee/dependencies_checks_configuration
Browse files Browse the repository at this point in the history
Improve dependencies checks configuration
  • Loading branch information
andrzej-mag authored Mar 7, 2022
2 parents eb7681c + d4425e7 commit e958887
Show file tree
Hide file tree
Showing 18 changed files with 5,259 additions and 1,246 deletions.
54 changes: 25 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Asynchronous dependency health checks library.

## Features
* User defined dependencies checks with flexible settings.
* Dependencies checks functions are executed asynchronously as isolated processes.
* Dependencies checks functions are executed asynchronously.
* Built-in `Plug` module providing customizable response for a http health-check endpoint.
* Checks states are stored in an ETS table, which means practically unlimited requests per second
processing capacity.
* Support for multiple independent `Existence` instances and associated health-checks
endpoints (example use case: separate Kubernetes readiness and liveness http probes).
* Checks states are stored and accessed using a dedicated ETS tables per `Existence` instance,
which means practically unlimited requests per second processing capacity.

## Installation
Add library to application dependencies:
Add `Existence` library to your application dependencies:
```elixir
def deps do
[
Expand All @@ -20,32 +22,26 @@ end
```

## Usage
Start library child in your application supervisor:
Define dependencies checks functions MFA's and start `Existence` child with your application
supervisor
```elixir
defmodule MyApp.Application do
use Application

def start(_type, _args) do
children = [Existence]
health_checks = [
check_1: %{mfa: {MyApp.Checks, :check_1, []}},
check_2: %{mfa: {MyApp.Checks, :check_2, []}}
]

children = [{Existence, checks: health_checks}]

opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
```

Configure dependencies checks in your application configuration file, for example:
```elixir
#config/config.exs
config :my_app, Existence,
check_1: %{
mfa: {MyApp.Checks, :check_1, []}
},
check_2: %{
mfa: {MyApp.Checks, :check_2, []}
}
```

Declare your dependencies checks functions:
```elixir
defmodule MyApp.Checks do
Expand All @@ -54,6 +50,16 @@ defmodule MyApp.Checks do
end
```

Configure your Phoenix router to respond to the `/healthcheck` endpoint requests using for example
`Plug.Router.forward/2`:
```elixir
defmodule MyAppWeb.Router do
use MyAppWeb, :router

forward("/healthcheck", Existence.Plug)
end
```

Get current overall health-check state:
```elixir
iex> Existence.get_state()
Expand All @@ -66,16 +72,6 @@ iex> Existence.get_checks()
[check_1: :ok, check_2: :ok]
```

Configure your Phoenix router to respond to the `/healthcheck` endpoint requests using for example
`Plug.Router.forward/2`:
```elixir
defmodule MyAppWeb.Router do
use MyAppWeb, :router

forward("/healthcheck", Existence.Plug)
end
```

## TODO
- [ ] add `telemetry` event emitted on a health-check state change.
- [ ] add `telemetry` event emitted on an overall health-check state change.

Loading

0 comments on commit e958887

Please sign in to comment.