Skip to content

Commit 14c03d7

Browse files
committed
Fix conneciton pool
1 parent c7e690a commit 14c03d7

4 files changed

Lines changed: 65 additions & 5 deletions

File tree

apps/codebattle/lib/codebattle/code_check/checker.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ defmodule Codebattle.CodeCheck.Checker do
7575
defp maybe_emit_telemetry(_token, _meta), do: :ok
7676

7777
defp run_error_description(%{status: status} = result) when status in @failure_results do
78+
output_error = Map.get(result, :output_error)
79+
output = Map.get(result, :output)
80+
7881
description =
7982
cond do
80-
is_binary(result[:output_error]) and String.trim(result[:output_error]) != "" ->
81-
result[:output_error]
83+
is_binary(output_error) and String.trim(output_error) != "" ->
84+
output_error
8285

83-
is_binary(result[:output]) and String.trim(result[:output]) != "" ->
84-
result[:output]
86+
is_binary(output) and String.trim(output) != "" ->
87+
output
8588

8689
status in ["service_timeout", "timeout"] ->
8790
"Code check execution timed out"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
defmodule Codebattle.CodeCheck.CheckerTest.ExecutorStub do
2+
@moduledoc false
3+
4+
def call(token) do
5+
%{token | execution_error: RuntimeError.exception("executor failed")}
6+
end
7+
end
8+
9+
defmodule Codebattle.CodeCheck.CheckerTest do
10+
use Codebattle.DataCase, async: false
11+
12+
alias Codebattle.CodeCheck.Checker
13+
alias Codebattle.CodeCheck.Result.V2
14+
15+
setup do
16+
previous_executor = Application.get_env(:codebattle, :checker_executor)
17+
Application.put_env(:codebattle, :checker_executor, Codebattle.CodeCheck.CheckerTest.ExecutorStub)
18+
FunWithFlags.disable(:use_remote_zig_executor)
19+
20+
on_exit(fn ->
21+
case previous_executor do
22+
nil -> Application.delete_env(:codebattle, :checker_executor)
23+
executor -> Application.put_env(:codebattle, :checker_executor, executor)
24+
end
25+
26+
FunWithFlags.disable(:use_remote_zig_executor)
27+
end)
28+
29+
:ok
30+
end
31+
32+
test "handles struct result when building run error description" do
33+
task = insert(:task)
34+
35+
assert %V2{status: "service_failure"} =
36+
Checker.call(task, "any_solution", "js", %{game_id: 1, user_id: 1})
37+
end
38+
end

config/runtime.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ config :codebattle, Codebattle.Repo,
4242
password: System.get_env("CODEBATTLE_DB_PASSWORD"),
4343
hostname: System.get_env("CODEBATTLE_DB_HOSTNAME"),
4444
database: System.get_env("CODEBATTLE_DB_NAME"),
45-
pool_size: "CODEBATTLE_POOL_SIZE" |> System.get_env("10") |> String.to_integer(),
45+
pool_size: "CODEBATTLE_POOL_SIZE" |> System.get_env("20") |> String.to_integer(),
46+
queue_target: "CODEBATTLE_DB_QUEUE_TARGET" |> System.get_env("2000") |> String.to_integer(),
47+
queue_interval: "CODEBATTLE_DB_QUEUE_INTERVAL" |> System.get_env("5000") |> String.to_integer(),
4648
log_level: :error
4749

4850
config :codebattle, CodebattleWeb.BotEndpoint,

k8s/app-chart/templates/zig_runner_deployment.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,26 @@ spec:
5555
{{- end }}
5656
containers:
5757
- name: "runner"
58+
securityContext:
59+
privileged: true
60+
allowPrivilegeEscalation: true
61+
runAsUser: 0
62+
runAsGroup: 0
63+
seccompProfile:
64+
type: Unconfined
5865
env:
5966
- name: DEBUG
6067
value: {{ $.Values.zigRunners.env.DEBUG | quote }}
68+
{{- if eq .name "csharp" }}
69+
- name: HOME
70+
value: /tmp
71+
- name: DOTNET_CLI_HOME
72+
value: /tmp
73+
- name: NUGET_PACKAGES
74+
value: /tmp/.nuget/packages
75+
- name: NUGET_HTTP_CACHE_PATH
76+
value: /tmp/.nuget/http-cache
77+
{{- end }}
6178
resources:
6279
{{- toYaml $.Values.zigRunners.resources | nindent 12 }}
6380
imagePullPolicy: Always

0 commit comments

Comments
 (0)