Merge pull request #10770 from demarches-simplifiees/US/fix-timeouting-task-fixing-champs-commune
ETQ operateur DS, je souhaite pouvoir corriger les champs de type commune ayant de la bad data
This commit is contained in:
commit
36247a4b6d
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 }
|
DEFAULT_INSTRUCTEUR_EMAIL = ENV.fetch('DEFAULT_INSTRUCTEUR_EMAIL') { CONTACT_EMAIL }
|
||||||
|
|
||||||
def collection
|
def collection
|
||||||
Champs::CommuneChamp.where.not(value: nil)
|
Champs::CommuneChamp.select(:id, :value, :external_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(champ)
|
def process(champ)
|
||||||
|
return if !(champ.value.present? && champ.external_id.blank?)
|
||||||
|
champ.reload
|
||||||
return if !fixable?(champ)
|
return if !fixable?(champ)
|
||||||
|
|
||||||
response = APIGeoService.commune_by_name_or_postal_code(champ.value)
|
response = APIGeoService.commune_by_name_or_postal_code(champ.value)
|
||||||
|
@ -36,7 +38,7 @@ module Maintenance
|
||||||
end
|
end
|
||||||
|
|
||||||
def count
|
def count
|
||||||
# 2.4M champs, count is not an option
|
# osf, count is not an option
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -61,7 +63,7 @@ module Maintenance
|
||||||
end
|
end
|
||||||
|
|
||||||
def fixable?(champ)
|
def fixable?(champ)
|
||||||
champ.value.present? && [champ.dossier.en_instruction? || champ.dossier.en_construction?]
|
champ.dossier.en_instruction? || champ.dossier.en_construction?
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify(message, champ) = Sentry.capture_message(message, extra: { champ: })
|
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(:procedure) { create(:procedure, types_de_champ_public: [{ type: :communes }]) }
|
||||||
let(:dossier) { create(:dossier, state, :with_populated_champs, procedure:) }
|
let(:dossier) { create(:dossier, state, :with_populated_champs, procedure:) }
|
||||||
let(:champ) { dossier.champs.first }
|
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
|
context 'when search find one result', vcr: { cassette_name: 'fix-champs-commune-with-one-results' } do
|
||||||
let(:state) { [:en_instruction, :en_construction].sample }
|
let(:state) { [:en_instruction, :en_construction].sample }
|
||||||
|
|
Loading…
Reference in a new issue