Skip to content

Instantly share code, notes, and snippets.

@pythonandchips
Last active July 22, 2020 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythonandchips/0e7613fbffc9ced25f459657361e2bbb to your computer and use it in GitHub Desktop.
Save pythonandchips/0e7613fbffc9ced25f459657361e2bbb to your computer and use it in GitHub Desktop.
Get count of overdue invoice per company.
switch_to_slave_db
companies = Company.joins(:subscription).merge(Subscription.live)
companies_count = companies.count
progress_bar = ProgressBar.new(companies_count)
ProgressBar.new(companies_count)
companies.find_each do |company|
Rails.logger.info({
event: "COMPANY_OVERDUE_INVOICE_COUNT",
company_id: company.id,
active: company.is_active?,
count: company.invoices.overdue.where.not(cached_net_value: 0).unpaid.count
}.to_json)
progress_bar.increment!
end
@djmb
Copy link

djmb commented Jul 22, 2020

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment