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

Add post-sync hook (#1479)

This commit is contained in:
Zach Gollwitzer 2024-11-20 11:01:52 -05:00 committed by GitHub
parent d1b506d16c
commit e641cfccd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 14 deletions

View file

@ -8,32 +8,27 @@ class Sync < ApplicationRecord
def perform
start!
syncable.sync_data(start_date: start_date)
complete!
rescue StandardError => error
fail! error
raise error if Rails.env.development?
begin
syncable.sync_data(start_date: start_date)
complete!
rescue StandardError => error
fail! error
raise error if Rails.env.development?
ensure
syncable.post_sync
end
end
private
def family
syncable.is_a?(Family) ? syncable : syncable.family
end
def start!
update! status: :syncing
end
def complete!
update! status: :completed, last_ran_at: Time.current
family.broadcast_refresh
end
def fail!(error)
update! status: :failed, error: error.message, last_ran_at: Time.current
family.broadcast_refresh
end
end