Skip to content

Commit 9a92641

Browse files
committed
Add custom round times
1 parent cc02c57 commit 9a92641

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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) -

services/app/config/config.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ config :codebattle, user_rank_server: true
8181
config :fun_with_flags, :cache, enabled: true
8282
config :fun_with_flags, :cache_bust_notifications, enabled: false
8383

84-
config :fun_with_flags, :persistence,
85-
adapter: FunWithFlags.Store.Persistent.Ecto,
86-
repo: Codebattle.Repo,
87-
ecto_table_name: "feature_flags"
88-
8984
config :fun_with_flags, :persistence,
9085
adapter: FunWithFlags.Store.Persistent.Ecto,
9186
repo: Codebattle.Repo,

services/app/config/releases.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ config :codebattle, host: codebattle_host
8888
config :codebattle,
8989
jitsi_api_key: System.get_env("JITSI_API_KEY", "")
9090

91-
<<<<<<< Updated upstream
9291
config :codebattle, k8s_namespace: System.get_env("KUBERNETES_NAMESPACE", "default")
93-
config :codebattle, record_games: record_games
94-
config :codebattle, show_extension_popup: show_extension_popup
95-
=======
96-
>>>>>>> Stashed changes
9792
config :codebattle, tournament_rematch_timeout_ms: tournament_rematch_timeout_ms
9893

9994
config :phoenix_meta_tags,

0 commit comments

Comments
 (0)