mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
* Fix syncing issues with new connections and accounts.. - Keep SimpleFin institution metadata strictly per account (`simplefin_accounts.org_data`). - Relax `simplefin_items` institution constraints to allow creating items before org data exists. - Remove code that copied the first account’s `org` onto `simplefin_items`. * Improve Simplefin Sync • SimpleFin: family “Sync” includes SimpleFin items; importer does unbounded discovery (with pending=1 fallback) before windowed fetch, for both regular and first syncs. • Stop populating item‑level institution fields; keep institution metadata per account. • Relax NOT NULL on item institution fields. • Post‑sync dashboard broadcasts are now guarded (UI cannot fail the job). • Show a friendly “daily refresh limit” banner on the SimpleFin card when the latest sync is rate‑limited. • Add bin/rails sure:simplefin:debug[ITEM_ID] to print latest sync, snapshot account count, simplefin_accounts count, and unlinked list. * Fixed double‑quoted strings, spacing around array brackets and commas * chore: ignore local .junie files * - Broadcast error logs now include full backtraces - SimpleFin discovery logic deduplicated fixed - app/models/simplefin_item/importer.rb --Added a concise docstring for perform_account_discovery describing purpose, steps, and side‑effects. --Added a docstring for fetch_accounts_data describing params and return value.
36 lines
1.4 KiB
Ruby
36 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
namespace :sure do
|
|
namespace :simplefin do
|
|
desc "Print debug info for a SimpleFin item: latest sync, snapshot accounts, simplefin_accounts, and unlinked list"
|
|
task :debug, [ :item_id ] => :environment do |_, args|
|
|
unless args[:item_id].present?
|
|
puts({ error: "usage", example: "bin/rails sure:simplefin:debug[ITEM_ID]" }.to_json)
|
|
exit 1
|
|
end
|
|
|
|
item = SimplefinItem.find(args[:item_id])
|
|
latest_sync = item.syncs.order(created_at: :desc).first
|
|
# Our model stores the latest snapshot directly on the item (`raw_payload`).
|
|
snapshot_accounts = item.raw_payload&.dig(:accounts)&.size
|
|
unlinked = item.simplefin_accounts.left_joins(:account).where(accounts: { id: nil })
|
|
|
|
out = {
|
|
item_id: item.id,
|
|
name: item.name,
|
|
last_synced_at: item.last_synced_at,
|
|
latest_sync: latest_sync&.attributes&.slice("id", "status", "error", "status_text", "created_at", "completed_at"),
|
|
snapshot_accounts: snapshot_accounts,
|
|
simplefin_accounts_count: item.simplefin_accounts.count,
|
|
unlinked_count: unlinked.count,
|
|
unlinked: unlinked.limit(20).map { |sfa| { id: sfa.id, upstream_id: sfa.account_id, name: sfa.name } }
|
|
}
|
|
|
|
puts out.to_json
|
|
rescue => e
|
|
puts({ error: e.class.name, message: e.message, backtrace: e.backtrace&.take(3) }.to_json)
|
|
exit 1
|
|
end
|
|
end
|
|
end
|