I want to run a task separate from my main application with connection to the database.
The task looks something like
defmodule MyService.Task do
def call do
Application.load(:my_service)
{:ok, _, _} = Ecto.Migrator.with_repo(MyService.Repo, fn repo ->
do_some_work(repo)
end)
end
end
In do_some_work(repo)
I simply schedule some jobs using Oban.
I am running it with eval
bin/my_service eval "MyService.Task.call()"
However it times out after 15s.
Postgrex.Protocol (#PID<0.274.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.165.0> timed out because it queued and checked out the
main ** (DBConnection.ConnectionError) connection is closed because of an error, disconnect or timeout
main (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
main (ecto 3.8.4) lib/ecto/repo/schema.ex:744: Ecto.Repo.Schema.apply/4 main (ecto 3.8.4) lib/ecto/repo/schema.ex:367: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
main (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:1222: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4 main (db_connection 2.4.2) lib/db_connection.ex:865: DBConnection.transaction/3 main (oban 2.12.1) lib/oban/queue/basic_engine.ex:53: Oban.Queue.BasicEngine.insert_job/2 main (oban 2.12.1) lib/oban/queue/engine.ex:234: anonymous fn/3 in Oban.Queue.Engine.with_span/4
Is there a way to configure the timeout for the migrator?
Something like
Ecto.Migrator.with_repo(MyService.Repo, fn repo ->
do_some_work(repo)
end, timeout: 1200_000)
or probably change the Repo config like
Application.load(:my_service)
config = Application.get_env(:my_service, MyService.Repo) |> Keyword.put(:timeout, 1200_000)
Application.put_env(:my_service, MyService.Repo, config)
Ecto.Migrator.with_repo(MyService.Repo, fn repo ->
do_some_work(repo)
end)