mirror of
https://github.com/we-promise/sure.git
synced 2026-09-05 06:41:08 +00:00
* Refresh Plaid transactions during scheduled sync * Refresh Plaid transactions for provider-wide sync * Refresh Plaid transactions on login sync * Document Plaid refresh follow-up sync * Contain automatic Plaid refresh failures
24 lines
687 B
Ruby
24 lines
687 B
Ruby
module AutoSync
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
before_action :sync_family, if: :family_needs_auto_sync?
|
|
end
|
|
|
|
private
|
|
def sync_family
|
|
Current.family.request_plaid_transactions_refreshes_later(source: "AutoSync")
|
|
Current.family.sync_later
|
|
end
|
|
|
|
def family_needs_auto_sync?
|
|
return false unless Current.family&.accounts&.active&.any?
|
|
return false if (Current.family.last_sync_created_at&.to_date || 1.day.ago) >= Date.current
|
|
return false unless Current.family.auto_sync_on_login
|
|
|
|
Rails.logger.info "Auto-syncing family #{Current.family.id}, last sync was #{Current.family.last_sync_created_at}"
|
|
|
|
true
|
|
end
|
|
end
|