fix(fix_champs_commune_having_value_but_not_external_id_task): timeouting despite classic pattern to find all champs for a specific type. lighten request by selecting only :id and processing batches
This commit is contained in:
parent
3e1bcb35d6
commit
18137b176c
2 changed files with 8 additions and 4 deletions
|
@ -7,10 +7,12 @@ module Maintenance
|
|||
DEFAULT_INSTRUCTEUR_EMAIL = ENV.fetch('DEFAULT_INSTRUCTEUR_EMAIL') { CONTACT_EMAIL }
|
||||
|
||||
def collection
|
||||
Champs::CommuneChamp.where.not(value: nil)
|
||||
Champs::CommuneChamp.select(:id, :value, :external_id)
|
||||
end
|
||||
|
||||
def process(champ)
|
||||
return if !(champ.value.present? && champ.external_id.blank?)
|
||||
champ.reload
|
||||
return if !fixable?(champ)
|
||||
|
||||
response = APIGeoService.commune_by_name_or_postal_code(champ.value)
|
||||
|
@ -36,7 +38,7 @@ module Maintenance
|
|||
end
|
||||
|
||||
def count
|
||||
# 2.4M champs, count is not an option
|
||||
# osf, count is not an option
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -61,7 +63,7 @@ module Maintenance
|
|||
end
|
||||
|
||||
def fixable?(champ)
|
||||
champ.value.present? && [champ.dossier.en_instruction? || champ.dossier.en_construction?]
|
||||
champ.dossier.en_instruction? || champ.dossier.en_construction?
|
||||
end
|
||||
|
||||
def notify(message, champ) = Sentry.capture_message(message, extra: { champ: })
|
||||
|
|
|
@ -8,7 +8,9 @@ module Maintenance
|
|||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :communes }]) }
|
||||
let(:dossier) { create(:dossier, state, :with_populated_champs, procedure:) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
subject(:process) { described_class.process(champ) }
|
||||
subject(:process) do
|
||||
described_class.process(champ)
|
||||
end
|
||||
|
||||
context 'when search find one result', vcr: { cassette_name: 'fix-champs-commune-with-one-results' } do
|
||||
let(:state) { [:en_instruction, :en_construction].sample }
|
||||
|
|
Loading…
Reference in a new issue