{"action":"created","issue":{"url":"https://api.github.com/repos/bitwalker/libcluster/issues/109","repository_url":"https://api.github.com/repos/bitwalker/libcluster","labels_url":"https://api.github.com/repos/bitwalker/libcluster/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/bitwalker/libcluster/issues/109/comments","events_url":"https://api.github.com/repos/bitwalker/libcluster/issues/109/events","html_url":"https://github.com/bitwalker/libcluster/issues/109","id":496721055,"node_id":"MDU6SXNzdWU0OTY3MjEwNTU=","number":109,"title":"How to ensure that the cluster has connected before starting dependent GenServer","user":{"login":"danschultzer","id":1254724,"node_id":"MDQ6VXNlcjEyNTQ3MjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1254724?v=4","gravatar_id":"","url":"https://api.github.com/users/danschultzer","html_url":"https://github.com/danschultzer","followers_url":"https://api.github.com/users/danschultzer/followers","following_url":"https://api.github.com/users/danschultzer/following{/other_user}","gists_url":"https://api.github.com/users/danschultzer/gists{/gist_id}","starred_url":"https://api.github.com/users/danschultzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danschultzer/subscriptions","organizations_url":"https://api.github.com/users/danschultzer/orgs","repos_url":"https://api.github.com/users/danschultzer/repos","events_url":"https://api.github.com/users/danschultzer/events{/privacy}","received_events_url":"https://api.github.com/users/danschultzer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-09-22T01:42:27Z","updated_at":"2019-09-22T03:08:58Z","closed_at":null,"author_association":"NONE","body":"I may start my application like this:\r\n\r\n```elixir\r\ndefmodule MyApp.Application do\r\n  use Application\r\n\r\n  def start(_type, _args) do\r\n    topologies = [\r\n      example: [\r\n        strategy: Cluster.Strategy.Epmd,\r\n        config: [hosts: [:\"a@127.0.0.1\", :\"b@127.0.0.1\"]],\r\n      ]\r\n    ]\r\n    children = [\r\n      {Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},\r\n      {Pow.Store.Backend.MnesiaCache, extra_db_nodes: Node.list()}\r\n    ]\r\n    Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)\r\n  end\r\nend\r\n```\r\n\r\nThe `Pow.Store.Backend.MnesiaCache` is a GenServer that will connect to an Mnesia cluster if there are any connected nodes that's also running Mnesia. However since `Node.list/0` will just return an empty list here, I need to make sure that libcluster already have connected before calling `Node.list/0` for `MnesiaCache`.\r\n\r\nWhat would be the best way to deal with this?\r\n\r\nAlso, thanks for this library @bitwalker!"},"comment":{"url":"https://api.github.com/repos/bitwalker/libcluster/issues/comments/533845969","html_url":"https://github.com/bitwalker/libcluster/issues/109#issuecomment-533845969","issue_url":"https://api.github.com/repos/bitwalker/libcluster/issues/109","id":533845969,"node_id":"MDEyOklzc3VlQ29tbWVudDUzMzg0NTk2OQ==","user":{"login":"danschultzer","id":1254724,"node_id":"MDQ6VXNlcjEyNTQ3MjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1254724?v=4","gravatar_id":"","url":"https://api.github.com/users/danschultzer","html_url":"https://github.com/danschultzer","followers_url":"https://api.github.com/users/danschultzer/followers","following_url":"https://api.github.com/users/danschultzer/following{/other_user}","gists_url":"https://api.github.com/users/danschultzer/gists{/gist_id}","starred_url":"https://api.github.com/users/danschultzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danschultzer/subscriptions","organizations_url":"https://api.github.com/users/danschultzer/orgs","repos_url":"https://api.github.com/users/danschultzer/repos","events_url":"https://api.github.com/users/danschultzer/events{/privacy}","received_events_url":"https://api.github.com/users/danschultzer/received_events","type":"User","site_admin":false},"created_at":"2019-09-22T03:08:58Z","updated_at":"2019-09-22T03:08:58Z","author_association":"NONE","body":"This is the idea I have had to solve it (https://github.com/pow-auth/pow_site/issues/10#issuecomment-533845299):\r\n\r\n```elixir\r\ndefmodule MyApp.MnesiaCacheCluster do\r\n  def connect_node(supervisor, node) do\r\n    node\r\n    |> :net_kernel.connect_node()\r\n    |> start_mnesia_cache(supervisor)\r\n  end\r\n\r\n  def start_mnesia_cache(true, supervisor) do\r\n    case Supervisor.start_child(supervisor, {Pow.Store.Backend.MnesiaCache, extra_db_nodes: Node.list()}) do\r\n      {:error, error} -> raise error\r\n      any             -> true\r\n    end\r\n  end\r\n  def start_mnesia_cache(any, _supervisor), do: any\r\nend\r\n```\r\n\r\n```elixir\r\ndefmodule MyApp.Application do\r\n  use Application\r\n\r\n  def start(_type, _args) do\r\n    topologies = [\r\n      k8s_example: [\r\n        strategy: Cluster.Strategy.Kubernetes,\r\n        config: [\r\n          # ...\r\n        ],\r\n        connect: {MyApp.MnesiaCacheCluster, :connect_node, [MyApp.ClusterSupervisor]}\r\n    ]\r\n\r\n    children = [\r\n      {Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},\r\n      # ...\r\n    ]\r\n\r\n    opts = [strategy: :one_for_one, name: MyApp.Supervisor]\r\n    Supervisor.start_link(children, opts)\r\n  end\r\nend\r\n```"}}
{"actor":{"display_login":"danschultzer"}}