Skip to content

Commit

Permalink
run remote node task during player tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushmau5 committed Mar 24, 2024
1 parent 6e9c60c commit d4068a2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/battleship_web/live/game_live/index.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule BattleshipWeb.GameLive.Index do
use BattleshipWeb, :live_view

alias Battleship.{Gameboard, Room, Player, Computer, Player.Name}
alias Battleship.{Gameboard, Room, Player, Computer, Player.Name, TaskRunner}
alias BattleshipWeb.Presence

@player_count_topic "player-join"
Expand Down Expand Up @@ -378,6 +378,17 @@ defmodule BattleshipWeb.GameLive.Index do
Presence.track(self(), @player_count_topic, socket.id, %{id: socket.id})
end

remote_node = TaskRunner.get_task_runner_node()

if remote_node != nil do
# Execute function on remote node
# This task updates the page view count
TaskRunner.run(
%{module: Accumulator.Tasks, function: :update_battleship_view_count, args: []},
remote_node
)
end

assign(socket, player_count: count)
end

Expand Down

0 comments on commit d4068a2

Please sign in to comment.