mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 07:25:19 +02:00
Report high duplicate sync counts to Sentry
This commit is contained in:
parent
267692d297
commit
0079710d47
1 changed files with 14 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
||||||
class Sync < ApplicationRecord
|
class Sync < ApplicationRecord
|
||||||
include AASM
|
include AASM
|
||||||
|
|
||||||
|
Error = Class.new(StandardError)
|
||||||
|
|
||||||
belongs_to :syncable, polymorphic: true
|
belongs_to :syncable, polymorphic: true
|
||||||
|
|
||||||
belongs_to :parent, class_name: "Sync", optional: true
|
belongs_to :parent, class_name: "Sync", optional: true
|
||||||
|
@ -18,7 +20,7 @@ class Sync < ApplicationRecord
|
||||||
state :completed
|
state :completed
|
||||||
state :failed
|
state :failed
|
||||||
|
|
||||||
event :start do
|
event :start, after_commit: :report_warnings do
|
||||||
transitions from: :pending, to: :syncing
|
transitions from: :pending, to: :syncing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -90,6 +92,17 @@ class Sync < ApplicationRecord
|
||||||
end
|
end
|
||||||
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
|
def window_valid
|
||||||
if window_start_date && window_end_date && window_start_date > window_end_date
|
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")
|
errors.add(:window_end_date, "must be greater than window_start_date")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue