Skip to content

Commit

Permalink
fix(current-usage): Manage connection pools with parallel threads (#2077
Browse files Browse the repository at this point in the history
)

## Context

This PR follows #2076

## Description

It tries to fix an issue with the connection pool:
```
could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use (ActiveRecord::ConnectionTimeoutError)
```
  • Loading branch information
vincent-pochet authored May 28, 2024
1 parent f957323 commit 3c948b1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/services/invoices/customer_usage_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def add_charge_fees
.order(Arel.sql('lower(unaccent(billable_metrics.name)) ASC'))

invoice.fees = Parallel.flat_map(query.all, in_threads: ENV['LAGO_PARALLEL_THREADS_COUNT']&.to_i || 1) do |charge|
charge_usage(charge)
ActiveRecord::Base.connection_pool.with_connection do
charge_usage(charge)
end
end
end

Expand Down

0 comments on commit 3c948b1

Please sign in to comment.