Skip to content

Commit 3162322

Browse files
committedMar 12, 2025·
Fix tournament cancel
1 parent a4f5bdb commit 3162322

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
 

‎services/app/apps/codebattle/lib/codebattle/game/context.ex

+11
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ defmodule Codebattle.Game.Context do
235235
game_id |> get_game!() |> Engine.trigger_timeout()
236236
end
237237

238+
@spec terminate_tournament_games(tournament_id) :: :ok
239+
def terminate_tournament_games(tournament_id) do
240+
Game
241+
|> where([g], g.tournament_id == ^tournament_id)
242+
|> where([g], g.state == "playing")
243+
|> select([g], g.id)
244+
|> Repo.all()
245+
|> Enum.each(fn game_id -> Engine.terminate_game(game_id) end)
246+
|> dbg()
247+
end
248+
238249
@spec terminate_game(game_id | Game.t()) :: :ok
239250
def terminate_game(%Game{} = game) do
240251
Engine.terminate_game(game)

‎services/app/apps/codebattle/lib/codebattle/game/engine.ex

+6
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ defmodule Codebattle.Game.Engine do
238238
end
239239
end
240240

241+
@spec terminate_game(game_id :: integer | Game.t()) :: :ok
242+
def terminate_game(game_id) when is_integer(game_id) do
243+
Game.GlobalSupervisor.terminate_game(game_id)
244+
:ok
245+
end
246+
241247
def terminate_game(%Game{} = game) do
242248
if game.is_live do
243249
Game.GlobalSupervisor.terminate_game(game.id)

‎services/app/apps/codebattle/lib/codebattle/tournament/strategy/base.ex

+1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ defmodule Codebattle.Tournament.Base do
254254
if can_moderate?(tournament, user) do
255255
new_tournament = tournament |> update_struct(%{state: "canceled"}) |> db_save!()
256256

257+
Game.Context.terminate_tournament_games(tournament.id)
257258
Tournament.GlobalSupervisor.terminate_tournament(tournament.id)
258259

259260
new_tournament

0 commit comments

Comments
 (0)
Please sign in to comment.