mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +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
|
@ -95,6 +95,29 @@ class Sync < ApplicationRecord
|
|||
parent&.finalize_if_all_children_finalized
|
||||
end
|
||||
|
||||
# If a sync is pending, we can adjust the window if new syncs are created with a wider window.
|
||||
def expand_window_if_needed(new_window_start_date, new_window_end_date)
|
||||
return unless pending?
|
||||
return if self.window_start_date.nil? && self.window_end_date.nil? # already as wide as possible
|
||||
|
||||
earliest_start_date = if self.window_start_date && new_window_start_date
|
||||
[self.window_start_date, new_window_start_date].min
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
latest_end_date = if self.window_end_date && new_window_end_date
|
||||
[self.window_end_date, new_window_end_date].max
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
update(
|
||||
window_start_date: earliest_start_date,
|
||||
window_end_date: latest_end_date
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
def log_status_change
|
||||
Rails.logger.info("changing from #{aasm.from_state} to #{aasm.to_state} (event: #{aasm.current_event})")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue