2024-02-29 08:32:52 -05:00
|
|
|
module Account::Syncable
|
2024-05-20 16:34:48 +02:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2024-07-10 11:22:59 -04:00
|
|
|
class_methods do
|
|
|
|
def sync(start_date: nil)
|
|
|
|
all.each { |a| a.sync_later(start_date: start_date) }
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
2024-05-20 16:34:48 +02:00
|
|
|
end
|
|
|
|
|
2024-07-10 11:22:59 -04:00
|
|
|
def syncing?
|
|
|
|
syncs.syncing.any?
|
2024-05-20 16:34:48 +02:00
|
|
|
end
|
|
|
|
|
2024-07-25 12:51:50 -04:00
|
|
|
def latest_sync_date
|
|
|
|
syncs.where.not(last_ran_at: nil).pluck(:last_ran_at).max&.to_date
|
|
|
|
end
|
|
|
|
|
|
|
|
def needs_sync?
|
|
|
|
latest_sync_date.nil? || latest_sync_date < Date.current
|
|
|
|
end
|
|
|
|
|
2024-07-10 11:22:59 -04:00
|
|
|
def sync_later(start_date: nil)
|
|
|
|
AccountSyncJob.perform_later(self, start_date: start_date)
|
2024-05-20 16:34:48 +02:00
|
|
|
end
|
|
|
|
|
2024-07-10 11:22:59 -04:00
|
|
|
def sync(start_date: nil)
|
|
|
|
Account::Sync.for(self, start_date: start_date).run
|
2024-05-20 16:34:48 +02:00
|
|
|
end
|
2024-02-29 08:32:52 -05:00
|
|
|
end
|