baruh

baruh

Getting timeout on running Ecto.Migrator.with_repo/2

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)

Marked As Solved

baruh

baruh

I end up simply increasing the timeout in my MyService.Repo config

config :my_service, MyService.Repo,
  url: "....",
  pool_size: 10,
  timeout: 1_200_000 # 20 mins

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement