Skip to content

Commit

Permalink
chore(champ): update error catching when fetching external data
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T committed Oct 27, 2023
1 parent 4a698f8 commit 508625b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/models/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ def describedby_id
end

def log_fetch_external_data_exception(exception)
exceptions = self.fetch_external_data_exceptions ||= []
exceptions << exception.inspect
update_column(:fetch_external_data_exceptions, exceptions)
update_column(:fetch_external_data_exceptions, [exception.inspect])
end

def fetch_external_data?
Expand All @@ -219,10 +217,14 @@ def poll_external_data?
false
end

def fetch_external_data_error?
fetch_external_data_exceptions.present? && self.external_id.present?
end

def fetch_external_data_pending?
# We don't have a good mechanism right now to know if the last fetch has errored. So, in order
# to ensure we don't poll to infinity, we stop after 5 minutes no matter what.
fetch_external_data? && poll_external_data? && external_id.present? && data.nil? && updated_at > 5.minutes.ago
fetch_external_data? && poll_external_data? && external_id.present? && data.nil? && !fetch_external_data_error?
end

def fetch_external_data
Expand Down Expand Up @@ -273,6 +275,7 @@ def cleanup_if_empty

def fetch_external_data_later
if fetch_external_data? && external_id.present? && data.nil?
update_column(:fetch_external_data_exceptions, [])
ChampFetchExternalDataJob.perform_later(self, external_id)
end
end
Expand Down

0 comments on commit 508625b

Please sign in to comment.