mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Handle nested child syncs (#2220)
This commit is contained in:
parent
8b857e9c8a
commit
2707a40a2a
3 changed files with 29 additions and 15 deletions
|
@ -47,7 +47,7 @@ class PlaidItem < ApplicationRecord
|
|||
|
||||
# Schedule account syncs
|
||||
accounts.each do |account|
|
||||
account.sync_later(start_date: start_date)
|
||||
account.sync_later(start_date: start_date, parent_sync: sync)
|
||||
end
|
||||
|
||||
Rails.logger.info("Plaid data fetched and loaded")
|
||||
|
|
|
@ -22,9 +22,8 @@ class Sync < ApplicationRecord
|
|||
data = syncable.sync_data(self, start_date: start_date)
|
||||
update!(data: data) if data
|
||||
|
||||
complete! unless has_pending_child_syncs?
|
||||
|
||||
unless has_pending_child_syncs?
|
||||
complete!
|
||||
Rails.logger.info("Sync completed, starting post-sync")
|
||||
syncable.post_sync(self)
|
||||
Rails.logger.info("Post-sync completed")
|
||||
|
@ -33,10 +32,7 @@ class Sync < ApplicationRecord
|
|||
fail! error
|
||||
raise error if Rails.env.development?
|
||||
ensure
|
||||
if has_parent?
|
||||
Rails.logger.info("notifying parent sync id=#{parent_id} of completion")
|
||||
notify_parent_of_completion!
|
||||
end
|
||||
notify_parent_of_completion! if has_parent?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -49,6 +45,10 @@ class Sync < ApplicationRecord
|
|||
|
||||
unless has_pending_child_syncs?
|
||||
complete!
|
||||
|
||||
# If this sync is both a child and a parent, we need to notify the parent of completion
|
||||
notify_parent_of_completion! if has_parent?
|
||||
|
||||
syncable.post_sync(self)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue