mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Fix attribute locking namespace conflict, duplicate syncs
This commit is contained in:
parent
ab5bce3462
commit
137219c121
11 changed files with 87 additions and 28 deletions
|
@ -9,20 +9,28 @@ module Syncable
|
|||
raise NotImplementedError, "Subclasses must implement the syncing? method"
|
||||
end
|
||||
|
||||
# Schedules a sync for syncable. If there is an existing sync pending/syncing for this syncable,
|
||||
# we do not create a new sync, and attempt to expand the sync window if needed.
|
||||
def sync_later(parent_sync: nil, window_start_date: nil, window_end_date: nil)
|
||||
Sync.transaction do
|
||||
# Since we're scheduling a new sync, mark old syncs for this syncable as stale
|
||||
self.syncs.incomplete.find_each(&:mark_stale!)
|
||||
with_lock do
|
||||
sync = self.syncs.incomplete.first
|
||||
|
||||
new_sync = self.syncs.create!(
|
||||
parent: parent_sync,
|
||||
window_start_date: window_start_date,
|
||||
window_end_date: window_end_date
|
||||
)
|
||||
if sync
|
||||
Rails.logger.info("There is an existing sync, expanding window if needed (#{sync.id})")
|
||||
sync.expand_window_if_needed(window_start_date, window_end_date)
|
||||
else
|
||||
sync = self.syncs.create!(
|
||||
parent: parent_sync,
|
||||
window_start_date: window_start_date,
|
||||
window_end_date: window_end_date
|
||||
)
|
||||
|
||||
SyncJob.perform_later(new_sync)
|
||||
SyncJob.perform_later(sync)
|
||||
end
|
||||
|
||||
new_sync
|
||||
sync
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue