-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapplication.ex
More file actions
37 lines (32 loc) · 1.2 KB
/
application.ex
File metadata and controls
37 lines (32 loc) · 1.2 KB
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
defmodule PostgresqlMessageQueue.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
PostgresqlMessageQueue.Persistence.Repo,
{PostgresqlMessageQueue.Persistence.NotificationListener,
name: PostgresqlMessageQueue.Persistence.Repo.NotificationListener,
repo: PostgresqlMessageQueue.Persistence.Repo},
PostgresqlMessageQueue.Messaging.MessageQueueWatcher,
message_queue_processor_spec()
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: PostgresqlMessageQueue.Supervisor]
Supervisor.start_link(children, opts)
end
defp message_queue_processor_spec() do
backoff_ms = fn attempt when is_integer(attempt) ->
base = 2 ** (attempt - 1) * 5 - 5
jitter = Enum.random(-base..base) |> Integer.floor_div(20)
base + jitter
end
{PostgresqlMessageQueue.Messaging.MessageQueueProcessor,
queue: PostgresqlMessageQueue.Messaging.global_queue(),
concurrency: 5,
backoff_ms: backoff_ms}
end
end