From d4068a2a4a5c8c0d8068cf1ed2d86a20acdde8b9 Mon Sep 17 00:00:00 2001 From: Aayush Kumar Sahu Date: Sun, 24 Mar 2024 22:58:06 +0530 Subject: [PATCH] run remote node task during player tracking --- lib/battleship_web/live/game_live/index.ex | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/battleship_web/live/game_live/index.ex b/lib/battleship_web/live/game_live/index.ex index 713cb96..e9e6a7d 100644 --- a/lib/battleship_web/live/game_live/index.ex +++ b/lib/battleship_web/live/game_live/index.ex @@ -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" @@ -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