mirror of
https://github.com/we-promise/sure.git
synced 2026-04-08 14:54:49 +00:00
* Fix record violation and add toggle for recurring feature * Run only once per sync cycle ( 30 sec ) * FIX params passing * Add collapsible to recurring section * FIX preferences error catch
40 lines
1.4 KiB
Ruby
40 lines
1.4 KiB
Ruby
class Family::SyncCompleteEvent
|
|
attr_reader :family
|
|
|
|
def initialize(family)
|
|
@family = family
|
|
end
|
|
|
|
def broadcast
|
|
# Dashboard partials can occasionally raise when rendered from background jobs
|
|
# (e.g., if intermediate series values are nil during a sync). Make broadcasts
|
|
# resilient so a post-sync UI refresh never causes the overall sync to report an error.
|
|
begin
|
|
family.broadcast_replace(
|
|
target: "balance-sheet",
|
|
partial: "pages/dashboard/balance_sheet",
|
|
locals: { balance_sheet: family.balance_sheet }
|
|
)
|
|
rescue => e
|
|
Rails.logger.error("Family::SyncCompleteEvent balance_sheet broadcast failed: #{e.message}\n#{e.backtrace&.join("\n")}")
|
|
end
|
|
|
|
begin
|
|
family.broadcast_replace(
|
|
target: "net-worth-chart",
|
|
partial: "pages/dashboard/net_worth_chart",
|
|
locals: { balance_sheet: family.balance_sheet, period: Period.last_30_days }
|
|
)
|
|
rescue => e
|
|
Rails.logger.error("Family::SyncCompleteEvent net_worth_chart broadcast failed: #{e.message}\n#{e.backtrace&.join("\n")}")
|
|
end
|
|
|
|
# Schedule recurring transaction pattern identification (debounced to run after all syncs complete)
|
|
begin
|
|
RecurringTransaction.identify_patterns_for(family)
|
|
rescue => e
|
|
Rails.logger.error("Family::SyncCompleteEvent recurring transaction identification failed: #{e.message}\n#{e.backtrace&.join("\n")}")
|
|
end
|
|
end
|
|
end
|