Skip to content

Instantly share code, notes, and snippets.

@bkono
Last active April 24, 2025 17:32
Show Gist options
  • Save bkono/38a6f91178701a845a7cc8e835a51a2e to your computer and use it in GitHub Desktop.
Save bkono/38a6f91178701a845a7cc8e835a51a2e to your computer and use it in GitHub Desktop.
defmodule MyApp.YugoSupervisor do
use Supervisor
require Logger
def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end
@impl true
def init(_init_arg) do
Logger.info("Initializing YugoSupervisor")
yugo_config = Application.fetch_env!(:myapp_ex, :yugo)
children = [
# IMAP Client specification
%{
id: Yugo.ScreenerClient,
start:
{Yugo.Client, :start_link,
[
[
name: :yugo_client,
server: yugo_config[:server],
username: yugo_config[:username],
password: yugo_config[:password],
mailbox: yugo_config[:mailbox],
ssl_verify: yugo_config[:ssl_verify]
]
]},
restart: :permanent,
shutdown: 5_000,
restart_delay: 3_000,
type: :worker
},
{MyApp.MailProcessor, Application.fetch_env!(:myapp_ex, MyApp.MailProcessor)}
]
# :rest_for_one means if a child process terminates, all siblings are restarted too
# max_restarts: 3 means allow 3 restarts
# max_seconds: 5 means within a 5 second window
Supervisor.init(children, strategy: :rest_for_one, max_restarts: 3, max_seconds: 5)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment