1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Transactional locks for sync completions (#2219)

* Transactional locks for sync completions

* Lower sync display logic tolerance in UI
This commit is contained in:
Zach Gollwitzer 2025-05-07 16:28:58 -04:00 committed by GitHub
parent 71be2a04ad
commit a07e9d40a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 11 deletions

View file

@ -41,10 +41,12 @@ class Sync < ApplicationRecord
end
def handle_child_completion_event
unless has_pending_child_syncs?
if has_failed_child_syncs?
fail!(Error.new("One or more child syncs failed"))
else
Sync.transaction do
# We need this to ensure 2 child syncs don't update the parent at the exact same time with different results
# and cause the sync to hang in "syncing" status indefinitely
self.lock!
unless has_pending_child_syncs?
complete!
syncable.post_sync(self)
end
@ -56,10 +58,6 @@ class Sync < ApplicationRecord
children.where(status: [ :pending, :syncing ]).any?
end
def has_failed_child_syncs?
children.where(status: :failed).any?
end
def has_parent?
parent_id.present?
end