Merge pull request #5978 from tchak/fix-data-fetch-jobs

Try to reduce the number of external data fetches
This commit is contained in:
Paul Chavard 2021-03-11 15:03:53 +01:00 committed by GitHub
commit 4c9305dbb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 19 deletions

View file

@ -1,16 +0,0 @@
class AnnuaireEducationUpdateJob < ApplicationJob
def perform(champ)
external_id = champ.external_id
if external_id.present?
data = APIEducation::AnnuaireEducationAdapter.new(external_id).to_params
if data.present?
champ.data = data
else
champ.external_id = nil
end
champ.save!
end
end
end

View file

@ -1,6 +1,6 @@
class ChampFetchExternalDataJob < ApplicationJob
def perform(champ)
if champ.external_id.present?
def perform(champ, external_id)
if champ.external_id == external_id && champ.data.nil?
data = champ.fetch_external_data
if data.present?

View file

@ -171,7 +171,7 @@ class Champ < ApplicationRecord
def fetch_external_data_later
if fetch_external_data? && external_id.present? && data.nil?
ChampFetchExternalDataJob.perform_later(self)
ChampFetchExternalDataJob.perform_later(self, external_id)
end
end