When the DB closes the connection I have a DBConnection.Error
.
I would like in this case to retry the query.
Is it something that could be handle by DBConnection or I have to handle myself?
(My use case is when a DB maintenance is applied by GCP)
There is no retry logic for queries in Ecto/DBConnection as far as I’m aware. The way you retry a query can be pretty implementation-specific so it’s hard to provide a generic interface for that.
Depending on how long the maintenance takes the implementation could be very different. E.g. if the DB was down for half an hour are you sure you still want to run that query? Etc.
It’s on GCP so the updated instance is available very quickly.
The issue is just with the established connection.
I’d go the no-so-happy-path and use a circuit breaker pattern for this if I really need to do such thing.
Are you sure there are not alternatives besides running a particular query every X time/retry?
Since I’m in an API call context if I do nothing the API returned a 500 
but that’s a proper response, no? the server side cannot connect to the DB due to a DB maintenance.
Just thinking out of the box, I’d go with a circuit breaker pattern that makes sure to close the connection if it’s open and try again. You could use something like this: ExternalService — external_service v1.1.4 or implement it yourself, which is also a good exercise from time to time 