Merge pull request #5978 from tchak/fix-data-fetch-jobs
Try to reduce the number of external data fetches
This commit is contained in:
commit
4c9305dbb1
3 changed files with 3 additions and 19 deletions
|
@ -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
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue