data(backfill): Champs::RnfChamp.value_json [±400 occurences]
This commit is contained in:
parent
d866309d45
commit
4bf5725d6d
3 changed files with 103 additions and 1 deletions
31
app/tasks/maintenance/populate_rnf_json_value_task.rb
Normal file
31
app/tasks/maintenance/populate_rnf_json_value_task.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue