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

Propagate child sync errors up to parent, fix sync status (#2232)

* Propagate child sync errors up to parent, fix sync status

* Remove testing error
This commit is contained in:
Zach Gollwitzer 2025-05-09 14:56:49 -04:00 committed by GitHub
parent 03e3899541
commit ab2cec55e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 29 additions and 22 deletions

View file

@ -28,8 +28,7 @@ class Sync < ApplicationRecord
Rails.logger.info("Post-sync completed")
end
rescue StandardError => error
fail! error
raise error if Rails.env.development?
fail! error, report_error: true
ensure
notify_parent_of_completion! if has_parent?
end
@ -43,7 +42,11 @@ class Sync < ApplicationRecord
self.lock!
unless has_pending_child_syncs?
complete!
if has_failed_child_syncs?
fail!(Error.new("One or more child syncs failed"))
else
complete!
end
# 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?
@ -58,6 +61,10 @@ 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
@ -76,12 +83,14 @@ class Sync < ApplicationRecord
update! status: :completed, last_ran_at: Time.current
end
def fail!(error)
def fail!(error, report_error: false)
Rails.logger.error("Sync failed: #{error.message}")
Sentry.capture_exception(error) do |scope|
scope.set_context("sync", { id: id, syncable_type: syncable_type, syncable_id: syncable_id })
scope.set_tags(sync_id: id)
if report_error
Sentry.capture_exception(error) do |scope|
scope.set_context("sync", { id: id, syncable_type: syncable_type, syncable_id: syncable_id })
scope.set_tags(sync_id: id)
end
end
update!(