@@ -32,6 +32,13 @@ defmodule Codebattle.Tournament.Base do
3232
3333 require Logger
3434
35+ @ custom_round_tiemouts_in_sec % {
36+ "elementary" => 3 * 60 ,
37+ "easy" => 5 * 60 ,
38+ "medium" => 10 * 60 ,
39+ "hard" => 25 * 60
40+ }
41+
3542 def add_player ( tournament , player ) do
3643 tournament_player = Tournament.Player . new! ( player )
3744 Tournament.Players . put_player ( tournament , tournament_player )
@@ -594,6 +601,8 @@ defmodule Codebattle.Tournament.Base do
594601
595602 defp bulk_create_round_games_and_matches ( batch , tournament , task_id ) do
596603 reset_task_ids = tournament . task_provider == "task_pack_per_round"
604+ task = get_task ( tournament , task_id )
605+ timeout_seconds = get_game_timeout ( tournament , task )
597606
598607 batch
599608 |> Enum . map ( fn
@@ -613,9 +622,9 @@ defmodule Codebattle.Tournament.Base do
613622 ref: match_id ,
614623 round_id: tournament . current_round_id ,
615624 state: "playing" ,
616- task: get_task ( tournament , task_id ) ,
625+ task: task ,
617626 waiting_room_name: tournament . waiting_room_name ,
618- timeout_seconds: get_game_timeout ( tournament ) ,
627+ timeout_seconds: timeout_seconds ,
619628 tournament_id: tournament . id ,
620629 type: game_type ( ) ,
621630 use_chat: tournament . use_chat ,
@@ -648,7 +657,7 @@ defmodule Codebattle.Tournament.Base do
648657 round_id: tournament . current_round_id ,
649658 state: "playing" ,
650659 task: task ,
651- timeout_seconds: get_game_timeout ( tournament ) ,
660+ timeout_seconds: get_game_timeout ( tournament , task ) ,
652661 waiting_room_name: tournament . waiting_room_name ,
653662 tournament_id: tournament . id ,
654663 type: game_type ( ) ,
@@ -751,7 +760,7 @@ defmodule Codebattle.Tournament.Base do
751760 round_id: tournament . current_round_id ,
752761 state: "playing" ,
753762 task: task ,
754- timeout_seconds: get_game_timeout ( tournament ) ,
763+ timeout_seconds: get_game_timeout ( tournament , task ) ,
755764 tournament_id: tournament . id ,
756765 type: game_type ( ) ,
757766 use_chat: tournament . use_chat ,
@@ -869,14 +878,26 @@ defmodule Codebattle.Tournament.Base do
869878 tournament
870879 end
871880
872- defp get_game_timeout ( tournament ) do
873- if use_waiting_room? ( tournament ) or tournament . type in [ "squad" , "swiss" ] do
874- min ( seconds_to_end_round ( tournament ) , tournament . match_timeout_seconds )
875- else
876- get_round_timeout_seconds ( tournament )
881+ defp get_game_timeout ( tournament , task ) do
882+ cond do
883+ FunWithFlags . enabled? ( :tournament_custom_timeout ) ->
884+ get_customer_round_timeout_seconds ( tournament , task )
885+
886+ use_waiting_room? ( tournament ) or tournament . type in [ "squad" ] ->
887+ min ( seconds_to_end_round ( tournament ) , tournament . match_timeout_seconds )
888+
889+ :default ->
890+ get_round_timeout_seconds ( tournament )
877891 end
878892 end
879893
894+ defp get_customer_round_timeout_seconds ( tournament , nil ) , do: get_round_timeout_seconds ( tournament )
895+
896+ defp get_customer_round_timeout_seconds ( tournament , task ) do
897+ Map . get ( @ custom_round_tiemouts_in_sec , task . level ) ||
898+ get_round_timeout_seconds ( tournament )
899+ end
900+
880901 defp seconds_to_end_round ( tournament ) do
881902 max (
882903 get_round_timeout_seconds ( tournament ) -
0 commit comments