Skip to content

Commit

Permalink
misc: rollback parallel as it raises DB connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed May 28, 2024
1 parent 3c948b1 commit 58a167a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/services/invoices/customer_usage_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ def add_charge_fees
.includes(:taxes, billable_metric: :organization, filters: {values: :billable_metric_filter})
.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|
ActiveRecord::Base.connection_pool.with_connection do
charge_usage(charge)
end
# TODO: fix issue with db connection pool
# invoice.fees = Parallel.flat_map(query.all, in_threads: ENV['LAGO_PARALLEL_THREADS_COUNT']&.to_i || 1) do |charge|
# ActiveRecord::Base.connection_pool.with_connection do
query.each do |charge|
invoice.fees << charge_usage(charge)
end
# end
# end
end

def charge_usage(charge)
Expand Down

0 comments on commit 58a167a

Please sign in to comment.