Skip to content

Commit

Permalink
Retry ListImport rows when they're not unique
Browse files Browse the repository at this point in the history
(Fixes SERVER-CH1)
  • Loading branch information
NuckChorris committed Oct 24, 2024
1 parent 5b28786 commit 97cfb39
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/models/list_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ def apply
Chewy.strategy(:atomic) do
each_with_index do |(media, data), index|
next if media.blank?
# Merge the library entries
le = LibraryEntry.where(user_id: user.id, media:).first_or_initialize
le.imported = true
le = merged_entry(le, data)
le.save! unless le.status.nil?
yield({ status: :running, total:, progress: index + 1 })
Retriable.retriable on: [ActiveRecord::RecordNotUnique] do
# Merge the library entries
le = LibraryEntry.where(user_id: user.id, media:).first_or_initialize
le.imported = true
le = merged_entry(le, data)
le.save! unless le.status.nil?
yield({ status: :running, total:, progress: index + 1 })
end
rescue StandardError => e
Sentry.capture_exception(e)
yield({
Expand Down

0 comments on commit 97cfb39

Please sign in to comment.