1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-04 21:15:19 +02:00

Add tagged logging to sync process (#1956)

* Add tagged logging to sync process

* Reduce logging in syncer

* Typo
This commit is contained in:
Zach Gollwitzer 2025-03-05 15:38:31 -05:00 committed by GitHub
parent cffafd23f0
commit 9627a6bf6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 86 additions and 39 deletions

View file

@ -6,38 +6,47 @@ class Sync < ApplicationRecord
scope :ordered, -> { order(created_at: :desc) }
def perform
start!
Rails.logger.tagged("Sync", id, syncable_type, syncable_id) do
start!
begin
data = syncable.sync_data(start_date: start_date)
update!(data: data) if data
complete!
rescue StandardError => error
fail! error
raise error if Rails.env.development?
ensure
syncable.post_sync
begin
data = syncable.sync_data(start_date: start_date)
update!(data: data) if data
complete!
rescue StandardError => error
fail! error
raise error if Rails.env.development?
ensure
Rails.logger.info("Sync completed, starting post-sync")
syncable.post_sync
Rails.logger.info("Post-sync completed")
end
end
end
private
def start!
Rails.logger.info("Starting sync")
update! status: :syncing
end
def complete!
Rails.logger.info("Sync completed")
update! status: :completed, last_ran_at: Time.current
end
def fail!(error)
Rails.logger.error("Sync failed: #{error.message}")
Sentry.capture_exception(error) do |scope|
scope.set_context("sync", { id: id })
scope.set_context("sync", { id: id, syncable_type: syncable_type, syncable_id: syncable_id })
end
update!(
status: :failed,
error: error.message,
error_backtrace: error.backtrace&.first(10),
last_ran_at: Time.current
)
end