-
Notifications
You must be signed in to change notification settings - Fork 7
/
.iex.exs
59 lines (49 loc) · 1.29 KB
/
.iex.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
alias PlugCheckup.Check
alias PlugCheckup.Options
defmodule Health.RandomCheck do
def call do
probability = :rand.uniform()
cond do
probability < 0.5 -> :ok
probability < 0.6 -> {:error, "Error"}
probability < 0.7 -> raise(RuntimeError, message: "Exception")
probability < 0.8 -> exit(:boom)
probability < 0.9 -> throw(:ball)
true -> :timer.sleep(2000)
end
end
end
defmodule MyRouter do
use Plug.Router
plug(:match)
plug(:dispatch)
self_checks = [
%Check{name: "random1", module: Health.RandomCheck, function: :call},
%Check{name: "random2", module: Health.RandomCheck, function: :call}
]
forward(
"/selfhealth",
to: PlugCheckup,
init_opts: Options.new(json_encoder: Jason, checks: self_checks, timeout: 1000)
)
deps_checks = [
%Check{name: "random1", module: Health.RandomCheck, function: :call},
%Check{name: "random2", module: Health.RandomCheck, function: :call}
]
forward(
"/dependencyhealth",
to: PlugCheckup,
init_opts:
Options.new(
json_encoder: Jason,
checks: deps_checks,
timeout: 3000,
pretty: false,
time_unit: :millisecond
)
)
match _ do
send_resp(conn, 404, "oops")
end
end
{:ok, _} = Plug.Adapters.Cowboy.http(MyRouter, [])