data(backfill): Champs::RnfChamp.value_json [±400 occurences]

This commit is contained in:
mfo 2024-08-19 17:07:43 +02:00
parent d866309d45
commit 4bf5725d6d
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
3 changed files with 103 additions and 1 deletions

View file

@ -0,0 +1,31 @@
# frozen_string_literal: true
module Maintenance
class PopulateRNFJSONValueTask < MaintenanceTasks::Task
include Dry::Monads[:result]
def collection
Champs::RNFChamp.where(value_json: nil)
# Collection to be iterated over
# Must be Active Record Relation or Array
end
def process(champ)
result = champ.fetch_external_data
case result
in Success(data)
begin
champ.update_with_external_data!(data:)
rescue ActiveRecord::RecordInvalid
# some champ might have dossier nil
end
else
# not found
end
end
def count
# not really interested in counting because it raises PG Statement timeout
end
end
end