Skip to content

Commit cc02c57

Browse files
committed
Minor improvements
1 parent 1f50dfb commit cc02c57

File tree

27 files changed

+252
-180
lines changed

27 files changed

+252
-180
lines changed

k8s/app-chart/values.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ codebattle:
2222
type: ClusterIP
2323
port: 4000
2424
env:
25-
CODEBATTLE_SHOW_EXTENSION_POPUP: "true"
26-
CODEBATTLE_USE_EXTERNAL_JS: "true"
27-
CODEBATTLE_CREATE_BOT_GAMES: "true"
28-
CODEBATTLE_IMPORT_GITHUB_TASKS: "true"
29-
CODEBATTLE_ALLOW_GUESTS: "true"
30-
CODEBATTLE_USE_PRESENCE: "true"
31-
CODEBATTLE_RECORD_GAMES: "true"
3225
CODEBATTLE_VERSION: "{{ .Values.version }}"
3326
CODEBATTLE_PORT: 4000
3427

@@ -66,7 +59,6 @@ runnerRust:
6659
image: codebattle/python:3.12.2
6760
replicaCount: 3
6861

69-
7062
resources: {}
7163
nodeSelector: {}
7264
tolerations: []

k8s/timoni/codebattle/values.cue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,5 @@ values: {
1919
}
2020
}
2121
env: {
22-
"CODEBATTLE_SHOW_EXTENSION_POPUP": true
23-
"CODEBATTLE_USE_EXTERNAL_JS": true
24-
"CODEBATTLE_CREATE_BOT_GAMES": true
25-
"CODEBATTLE_IMPORT_GITHUB_TASKS": true
26-
"CODEBATTLE_ALLOW_GUESTS": true
27-
"CODEBATTLE_USE_PRESENCE": true
28-
"CODEBATTLE_RECORD_GAMES": true
2922
}
3023
}

services/app/apps/codebattle/lib/codebattle/application.ex

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,12 @@ defmodule Codebattle.Application do
1515
config_path |> Config.Reader.read!() |> Application.put_all_env()
1616
end
1717

18-
github_tasks =
19-
if Application.get_env(:codebattle, :import_github_tasks) do
20-
[{Codebattle.TasksImporter, []}]
21-
else
22-
[]
23-
end
24-
25-
bot_games =
26-
if Application.get_env(:codebattle, :create_bot_games) do
27-
[{Codebattle.Bot.GameCreator, []}]
28-
else
29-
[]
30-
end
31-
32-
user_rank =
33-
if Application.get_env(:codebattle, :user_rank_server) do
34-
[{Codebattle.UsersRankUpdateServer, []}]
35-
else
36-
[]
37-
end
38-
3918
children =
4019
[
4120
{ChromicPDF, chromic_pdf_opts()},
21+
{Codebattle.TasksImporter, []},
22+
{Codebattle.UsersRankUpdateServer, []},
23+
{Codebattle.Bot.GameCreator, []},
4224
{Codebattle.ImageCache, []},
4325
{Codebattle.Repo, []},
4426
{Registry, keys: :unique, name: Codebattle.Registry},
@@ -65,7 +47,7 @@ defmodule Codebattle.Application do
6547
id: Codebattle.Chat.Lobby,
6648
start: {Codebattle.Chat, :start_link, [:lobby, %{message_ttl: to_timeout(hour: 8)}]}
6749
}
68-
] ++ github_tasks ++ bot_games ++ user_rank
50+
]
6951

7052
Supervisor.start_link(children,
7153
strategy: :one_for_one,

services/app/apps/codebattle/lib/codebattle/bot/game_creator.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Codebattle.Bot.GameCreator do
55
alias Codebattle.Bot
66
alias Codebattle.Game
77

8-
@timeout to_timeout(second: 3)
8+
@timeout Application.compile_env(:codebattle, :start_create_bot_timeout)
99

1010
@spec start_link([]) :: GenServer.on_start()
1111
def start_link(_) do
@@ -15,16 +15,22 @@ defmodule Codebattle.Bot.GameCreator do
1515
@impl GenServer
1616
def init(_state) do
1717
Process.send_after(self(), :create_bot_if_needed, @timeout)
18+
1819
{:ok, :noop}
1920
end
2021

2122
@impl GenServer
2223
def handle_info(:create_bot_if_needed, state) do
23-
for level <- Codebattle.Task.levels() do
24-
create_game(level)
24+
if FunWithFlags.enabled?(:skip_bot_games) do
25+
:noop
26+
else
27+
for level <- Codebattle.Task.levels() do
28+
create_game(level)
29+
end
30+
31+
Process.send_after(self(), :create_bot_if_needed, @timeout)
2532
end
2633

27-
Process.send_after(self(), :create_bot_if_needed, @timeout)
2834
{:noreply, state}
2935
end
3036

services/app/apps/codebattle/lib/codebattle/game/server.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule Codebattle.Game.Server do
4848

4949
state = %{
5050
game: game,
51-
is_record_games: Application.get_env(:codebattle, :record_games),
51+
is_record_games: !FunWithFlags.enabled?(:skip_record_games),
5252
playbook_state: %{records: [], id: 0}
5353
}
5454

services/app/apps/codebattle/lib/codebattle/tasks_importer.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ defmodule Codebattle.TasksImporter do
2525
# SERVER
2626
def init(state) do
2727
Logger.debug("Start Tasks Importer")
28+
2829
Process.send_after(self(), :run, to_timeout(second: 17))
30+
2931
{:ok, state}
3032
end
3133

3234
def handle_info(:run, state) do
33-
upsert(fetch_issues())
34-
Process.send_after(self(), :run, @timeout)
35+
if FunWithFlags.enabled?(:use_import_github_tasks) do
36+
upsert(fetch_issues())
37+
Process.send_after(self(), :run, @timeout)
38+
else
39+
:noop
40+
end
41+
3542
{:noreply, state}
3643
end
3744

services/app/apps/codebattle/lib/codebattle/users_rank_update_server.ex

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ defmodule Codebattle.UsersRankUpdateServer do
1919
# SERVER
2020
def init(_) do
2121
Process.send_after(self(), :work, @timeout)
22+
Process.send_after(self(), :subscribe, @timeout)
2223

23-
Codebattle.PubSub.subscribe("games")
2424
Logger.debug("Start UsersRankServer")
25+
2526
{:ok, true}
2627
end
2728

@@ -30,12 +31,26 @@ defmodule Codebattle.UsersRankUpdateServer do
3031
{:noreply, state}
3132
end
3233

33-
def handle_info(:work, state) do
34-
do_work()
35-
Process.send_after(self(), :work, @timeout)
34+
def handle_info(:subscribe, state) do
35+
if FunWithFlags.enabled?(:skip_user_rank_server) do
36+
:noop
37+
else
38+
Codebattle.PubSub.subscribe("games")
39+
end
40+
3641
{:noreply, state}
3742
end
3843

44+
def handle_info(:work, state) do
45+
if FunWithFlags.enabled?(:skip_user_rank_server) do
46+
:noop
47+
else
48+
do_work()
49+
Process.send_after(self(), :work, @timeout)
50+
{:noreply, state}
51+
end
52+
end
53+
3954
def handle_info(%{event: "game:finished", payload: %{tournament_id: nil}}, state) do
4055
do_work()
4156
{:noreply, state}

services/app/apps/codebattle/lib/codebattle_web/channels/main_channel.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defmodule CodebattleWeb.MainChannel do
1515
topic = "main:#{current_user.id}"
1616
Codebattle.PubSub.subscribe(topic)
1717

18-
if Application.get_env(:codebattle, :use_presence) do
18+
if !FunWithFlags.enabled?(:skip_presence) do
1919
send(self(), {:after_join, state})
2020
end
2121

services/app/apps/codebattle/lib/codebattle_web/controllers/root_controller.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ defmodule CodebattleWeb.RootController do
4141
end
4242
end
4343

44+
def maintenance(conn, _) do
45+
render(conn, "maintenance.html", layout: {LayoutView, "empty.html"})
46+
end
47+
4448
def feedback(conn, _) do
4549
render(conn, "feedback.xml")
4650
end

services/app/apps/codebattle/lib/codebattle_web/controllers/session_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule CodebattleWeb.SessionController do
55

66
def new(conn, _params) do
77
cond do
8-
Application.get_env(:codebattle, :use_only_token_auth) ->
8+
FunWithFlags.enabled?(:use_only_token_auth) ->
99
render(conn, "token_only.html")
1010

1111
Application.get_env(:codebattle, :use_local_password_auth) ->

0 commit comments

Comments
 (0)