diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2023-01-13 21:18:34 -0700 |
---|---|---|
committer | Simponic <loganhunt@simponic.xyz> | 2023-01-13 21:23:46 -0700 |
commit | 53be77e2c57bac6b861d7c3d1d2d6355816a823b (patch) | |
tree | bf2db793a3e0f416b411283547e7f58411f80d9e /lib/chessh/schema/player_session.ex | |
parent | 87e42b29f004f67df2512c133de626c2b0804477 (diff) | |
parent | 2b06f5bf47ec5f8f084dae8f015ca3677d753a7d (diff) | |
download | chessh-53be77e2c57bac6b861d7c3d1d2d6355816a823b.tar.gz chessh-53be77e2c57bac6b861d7c3d1d2d6355816a823b.zip |
Merge pull request #4 from Simponic/fix_pubkey
Fix pubkey
Diffstat (limited to 'lib/chessh/schema/player_session.ex')
-rw-r--r-- | lib/chessh/schema/player_session.ex | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/chessh/schema/player_session.ex b/lib/chessh/schema/player_session.ex index 8ca338c..b16519f 100644 --- a/lib/chessh/schema/player_session.ex +++ b/lib/chessh/schema/player_session.ex @@ -14,7 +14,7 @@ defmodule Chessh.PlayerSession do def changeset(player_session, attrs) do player_session - |> cast(attrs, [:login]) + |> cast(attrs, [:login, :node_id, :process]) end def concurrent_sessions(player) do @@ -58,12 +58,17 @@ defmodule Chessh.PlayerSession do "Creating session for player #{username} on node #{System.fetch_env!("NODE_ID")} with process #{inspect(self())}" ) - Repo.insert(%PlayerSession{ - login: DateTime.utc_now(), - node_id: System.fetch_env!("NODE_ID"), - player: player, - process: Utils.pid_to_str(self()) - }) + now = DateTime.utc_now() + + Repo.insert!( + %PlayerSession{ + login: now, + node_id: System.fetch_env!("NODE_ID"), + player: player, + process: Utils.pid_to_str(self()) + }, + on_conflict: :nothing + ) concurrent_sessions = PlayerSession.concurrent_sessions(player) |