diff options
| author | Simponic <loganhunt@simponic.xyz> | 2022-12-29 17:21:20 -0700 |
|---|---|---|
| committer | Simponic <loganhunt@simponic.xyz> | 2022-12-29 17:21:20 -0700 |
| commit | 1a2bdccf124de6207899f59538cc0ed2efc97b5a (patch) | |
| tree | 5b582023531c8df637881899ab64d5f5eddd7f3f /lib/chessh/application.ex | |
| parent | 10bc34245e8e1e3ba63fb0720d3bcfb1119db921 (diff) | |
| download | chessh-1a2bdccf124de6207899f59538cc0ed2efc97b5a.tar.gz chessh-1a2bdccf124de6207899f59538cc0ed2efc97b5a.zip | |
Add scalable nodes and user sessions
Diffstat (limited to 'lib/chessh/application.ex')
| -rw-r--r-- | lib/chessh/application.ex | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/chessh/application.ex b/lib/chessh/application.ex index 847dd98..4692489 100644 --- a/lib/chessh/application.ex +++ b/lib/chessh/application.ex @@ -1,9 +1,23 @@ defmodule Chessh.Application do + alias Chessh.{PlayerSession, Node} use Application + def initialize_player_sessions_on_node() do + # If we have more than one node running the ssh daemon, we'd want to ensure + # this is restarting after every potential crash. Otherwise the player sessions + # on the node would hang. + node_id = System.fetch_env!("NODE_ID") + Node.boot(node_id) + PlayerSession.delete_all_on_node(node_id) + end + def start(_, _) do children = [Chessh.Repo, Chessh.SSH.Daemon] opts = [strategy: :one_for_one, name: Chessh.Supervisor] - Supervisor.start_link(children, opts) + + with {:ok, pid} <- Supervisor.start_link(children, opts) do + initialize_player_sessions_on_node() + {:ok, pid} + end end end |
