mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 12:05:19 +02:00
Breaks our Plaid sync process out into more manageable classes. Notably, this moves the sync process to a distinct, 2-step flow: 1. Import stage - we first make API calls and import Plaid data to "mirror" tables 2. Processing stage - read the raw data, apply business rules, build internal domain models and sync balances This provides several benefits: - Plaid syncs can now be "replayed" without fetching API data again - Mirror tables provide better audit and debugging capabilities - Eliminates the "all or nothing" sync behavior that is currently in place, which is brittle
26 lines
680 B
Ruby
26 lines
680 B
Ruby
class PlaidItem::Syncer
|
|
attr_reader :plaid_item
|
|
|
|
def initialize(plaid_item)
|
|
@plaid_item = plaid_item
|
|
end
|
|
|
|
def perform_sync(sync)
|
|
# Loads item metadata, accounts, transactions, and other data to our DB
|
|
plaid_item.import_latest_plaid_data
|
|
|
|
# Processes the raw Plaid data and updates internal domain objects
|
|
plaid_item.process_accounts
|
|
|
|
# All data is synced, so we can now run an account sync to calculate historical balances and more
|
|
plaid_item.schedule_account_syncs(
|
|
parent_sync: sync,
|
|
window_start_date: sync.window_start_date,
|
|
window_end_date: sync.window_end_date
|
|
)
|
|
end
|
|
|
|
def perform_post_sync
|
|
# no-op
|
|
end
|
|
end
|