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

Report high duplicate sync counts to Sentry

This commit is contained in:
Zach Gollwitzer 2025-05-12 20:17:59 -04:00
parent 267692d297
commit 0079710d47

View file

@ -1,6 +1,8 @@
class Sync < ApplicationRecord
include AASM
Error = Class.new(StandardError)
belongs_to :syncable, polymorphic: true
belongs_to :parent, class_name: "Sync", optional: true
@ -18,7 +20,7 @@ class Sync < ApplicationRecord
state :completed
state :failed
event :start do
event :start, after_commit: :report_warnings do
transitions from: :pending, to: :syncing
end
@ -90,6 +92,17 @@ class Sync < ApplicationRecord
end
end
def report_warnings
todays_sync_count = syncable.syncs.where(created_at: Date.current.all_day).count
if todays_sync_count > 10
Sentry.capture_exception(
Error.new("#{syncable_type} (#{syncable.id}) has exceeded 10 syncs today (count: #{todays_sync_count})"),
level: :warning
)
end
end
def window_valid
if window_start_date && window_end_date && window_start_date > window_end_date
errors.add(:window_end_date, "must be greater than window_start_date")