Class: BudgetRefresherIncrementalWorker
- Inherits:
-
Object
- Object
- BudgetRefresherIncrementalWorker
- Includes:
- Sidekiq::Job, Workers::StatusBroadcastable
- Defined in:
- app/workers/budget_refresher_incremental_worker.rb
Overview
Incremental budget refresher worker that uses upserts instead of delete-all-reinsert.
This is faster and safer for frequent (hourly) refreshes.
Key differences from BudgetRefresherWorkerWithStatus:
- Uses incremental: true mode which performs upserts
- Does not delete existing facts before inserting
- Can be run more frequently without data loss risk
Usage:
BudgetRefresherIncrementalWorker.perform_async(year: 2026, month: 2)
BudgetRefresherIncrementalWorker.perform_async(current_month: true)
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
Methods included from Workers::StatusBroadcastable::Overrides
Instance Method Details
#perform(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/workers/budget_refresher_incremental_worker.rb', line 20 def perform( = {}) # Support current_month: true for scheduled jobs if [:current_month] year = Date.current.year month = Date.current.month else year = [:year].to_i month = [:month].to_i end total 5 at(1, "Initializing incremental 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 with incremental: true Analytic::BudgetFact.refresh_data_for_month(year, month, incremental: true) do |step, | # Steps 3-4 are for the main processing at(3 + (step.to_f / 100).round(1), ) if step && end at(4, 'Upserting budget facts...') at(5, 'Complete!') store redirect_to: "/reports/budget?company=all&date[year]=#{year}&date[month]=#{month}" end |