-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] distributing repo_poller worker jobs across multiple nodes
- Loading branch information
Showing
9 changed files
with
109 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule RepoPoller.ClusterConnector do | ||
use GenServer | ||
|
||
require Logger | ||
|
||
alias RepoPoller.Config | ||
|
||
def start_link(args) do | ||
GenServer.start_link(__MODULE__, args, []) | ||
end | ||
|
||
def init(_) do | ||
nodes = nodes() | ||
join_cluster(nodes) | ||
schedule_self_heal() | ||
|
||
{:ok, nil} | ||
end | ||
|
||
def handle_info(:self_heal, nil) do | ||
cluster_nodes = nodes() | ||
|
||
nodes = | ||
Node.list() | ||
|> Enum.filter(fn node -> | ||
Enum.member?(cluster_nodes, node) | ||
end) | ||
|
||
(cluster_nodes -- nodes) | ||
|> join_cluster() | ||
|
||
schedule_self_heal() | ||
{:noreply, nil} | ||
end | ||
|
||
defp schedule_self_heal() do | ||
Process.send_after(self(), :self_heal, 5000) | ||
end | ||
|
||
defp nodes() do | ||
Config.get_nodes() |> List.delete(Node.self()) | ||
end | ||
|
||
defp join_cluster(nodes) when is_list(nodes) do | ||
Enum.each(nodes, fn node -> | ||
Logger.info("joining node #{inspect(node)}") | ||
join_cluster(node) | ||
end) | ||
end | ||
|
||
defp join_cluster(node) do | ||
Horde.Cluster.join_hordes( | ||
RepoPoller.DistributedSupervisor, | ||
{RepoPoller.DistributedSupervisor, node} | ||
) | ||
|
||
Horde.Cluster.join_hordes( | ||
RepoPoller.DistributedRegistry, | ||
{RepoPoller.DistributedRegistry, node} | ||
) | ||
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,6 @@ defmodule RepoPoller.SetupQueueWorker do | |
exchange_options: [durable: true] | ||
) | ||
|
||
{:ok, :ignore} | ||
:ignore | ||
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
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
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