Created
April 17, 2019 13:58
-
-
Save athal7/3cafa2fa56eeb32fd3282dcfcdae93d9 to your computer and use it in GitHub Desktop.
mnesiac / libcluters / kube dns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Db.Application do | |
@moduledoc false | |
use Application | |
require Logger | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
init_cluster(System.get_env("CLUSTER_DNS"), System.get_env("CLUSTER")) | |
children = [ | |
supervisor(Db.Repo, []) | |
] | |
opts = [strategy: :one_for_one, name: Db.Supervisor] | |
Supervisor.start_link(children, opts) | |
end | |
defp init_cluster(nil, _), | |
do: Logger.warn("Cluster not initiated, missing service configuration") | |
defp init_cluster(_, nil), | |
do: Logger.warn("Cluster not initiated, missing application configuration") | |
defp init_cluster(service, application) do | |
topology = [ | |
myapp: [ | |
strategy: Elixir.Cluster.Strategy.Kubernetes.DNS, | |
config: [ | |
service: service, | |
application_name: application, | |
polling_interval: 10_000 | |
] | |
] | |
] | |
Application.put_env(:libcluster, :topologies, topology) | |
children = [{Cluster.Supervisor, [topology, [name: Db.LibclusterSupervisor]]}] | |
opts = [strategy: :one_for_one, name: Db.ClusterSupervisor] | |
Supervisor.start_link(children, opts) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Web.Application do | |
@moduledoc false | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
# Define workers and child supervisors to be supervised | |
children = [ | |
{Mnesiac.Supervisor, [Node.list(), [name: Web.MnesiacSupervisor]]}, | |
supervisor(Web.Endpoint, []) | |
] | |
opts = [strategy: :one_for_one, name: Web.Supervisor] | |
Supervisor.start_link(children, opts) | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment