Make `ClickhouseRepo` task timeouts configurable in CE (#4494)

* remove ch timeouts from ce

* just infinity

* make timeout configurable

* quadruple

* add test

* improve test

* fix test filtering in ci

* just don't compile the test in ee

* fix test in ee

* maybe this would work

* rm test

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
This commit is contained in:
ruslandoga 2024-09-09 16:20:06 +07:00 committed by GitHub
parent 0031d1487d
commit 9ba9e2abc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

@ -1,4 +1,6 @@
defmodule Plausible.ClickhouseRepo do
use Plausible
use Ecto.Repo,
otp_app: :plausible,
adapter: Ecto.Adapters.ClickHouse,
@ -23,9 +25,19 @@ defmodule Plausible.ClickhouseRepo do
max_concurrency = Keyword.get(opts, :max_concurrency, 3)
task_timeout =
on_ee do
@task_timeout
else
# Quadruple the repo timeout to ensure the task doesn't timeout before db_connection does.
# This maintains the default ratio (@task_timeout / default_timeout = 60_000 / 15_000 = 4).
ch_timeout = Keyword.fetch!(config(), :timeout)
max(ch_timeout * 4, @task_timeout)
end
Task.async_stream(queries, execute_with_tracing,
max_concurrency: max_concurrency,
timeout: @task_timeout
timeout: task_timeout
)
|> Enum.to_list()
|> Keyword.values()