File tree 3 files changed +18
-0
lines changed
services/app/apps/codebattle/lib/codebattle
3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -235,6 +235,17 @@ defmodule Codebattle.Game.Context do
235
235
game_id |> get_game! ( ) |> Engine . trigger_timeout ( )
236
236
end
237
237
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
+
238
249
@ spec terminate_game ( game_id | Game . t ( ) ) :: :ok
239
250
def terminate_game ( % Game { } = game ) do
240
251
Engine . terminate_game ( game )
Original file line number Diff line number Diff line change @@ -238,6 +238,12 @@ defmodule Codebattle.Game.Engine do
238
238
end
239
239
end
240
240
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
+
241
247
def terminate_game ( % Game { } = game ) do
242
248
if game . is_live do
243
249
Game.GlobalSupervisor . terminate_game ( game . id )
Original file line number Diff line number Diff line change @@ -254,6 +254,7 @@ defmodule Codebattle.Tournament.Base do
254
254
if can_moderate? ( tournament , user ) do
255
255
new_tournament = tournament |> update_struct ( % { state: "canceled" } ) |> db_save! ( )
256
256
257
+ Game.Context . terminate_tournament_games ( tournament . id )
257
258
Tournament.GlobalSupervisor . terminate_tournament ( tournament . id )
258
259
259
260
new_tournament
You can’t perform that action at this time.
0 commit comments