In Ecto, transactions can timeout. So this type of code:
Repo.transaction fn -> # Many thousands of expensive queries # And inserts end
This type of code might fail after 15 seconds, which is the default timeout.
In Ecto you can specify what the timeout should be for each operation. All functions that make a request to the database have the same same shared options of which
:timeout is one.
Repo.all(massive_query, timeout: 20_000)
The above query now times out after 20 seconds.
These shared options apply to a transaction as well. If you don’t care that a transaction is taking a long time you can set the timeout to
Repo.transaction(fn -> # Many thousands of expensive queries # And inserts end, timeout: :infinity)
Now this operation will be allowed to finish, despite the time it takes.Tweet