Class: BudgetRefresherWorkerWithStatus

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Workers::StatusBroadcastable
Defined in:
app/workers/budget_refresher_worker_with_status.rb

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/workers/budget_refresher_worker_with_status.rb', line 8

def perform(options = {})
  options = options.with_indifferent_access
  year = options[:year].to_i
  month = options[:month].to_i

  total 5
  at(1, "Initializing budget refresh for #{Date::MONTHNAMES[month]} #{year}...")

  at(2, 'Pre-loading reference data (projects, suppliers)...')

  at(3, 'Computing ledger and budget aggregates...')

  # Pass a progress callback to the refresh method
  Analytic::BudgetFact.refresh_data_for_month(year, month) do |step, message|
    # Steps 3-4 are for the main processing
    at(3 + (step.to_f / 100).round(1), message) if step && message
  end

  at(4, 'Batch inserting budget facts...')

  at(5, 'Complete!')
  store redirect_to: "/reports/budget?company=all&date[year]=#{year}&date[month]=#{month}"
end