Merge pull request #6354 from betagouv/remove-outdated-tasks
Suppression d'anciennes tâches Rake (#6354)
This commit is contained in:
commit
9f9e1fdab7
4 changed files with 0 additions and 121 deletions
|
@ -1,17 +0,0 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: migrate service organisme'
|
||||
task migrate_service_organisme: :environment do
|
||||
table = {
|
||||
'commune': 'collectivite_territoriale',
|
||||
'departement': 'collectivite_territoriale',
|
||||
'region': 'collectivite_territoriale',
|
||||
'prefecture': 'service_deconcentre_de_l_etat'
|
||||
}
|
||||
|
||||
table.each do |(old_name, new_name)|
|
||||
Service.where(type_organisme: old_name).update_all(type_organisme: new_name)
|
||||
end
|
||||
|
||||
AfterParty::TaskRecord.create version: '20190201121252'
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
require Rails.root.join("lib", "tasks", "task_helper")
|
||||
|
||||
namespace :fix_timestamps_of_migrated_dossiers do
|
||||
desc 'Fix the timestamps of dossiers affected by the faulty PJ migration'
|
||||
task run: :environment do
|
||||
affected_time_range = Time.utc(2019, 6, 4, 8, 0)..Time.utc(2019, 6, 4, 18, 0)
|
||||
dossiers = Dossier.with_discarded.includes(:groupe_instructeur).where(groupe_instructeurs: { procedure_id: 0..1000 }).where(updated_at: affected_time_range)
|
||||
|
||||
progress = ProgressReport.new(dossiers.count)
|
||||
|
||||
dossiers.find_each do |dossier|
|
||||
fixed_updated_at = dossier.processed_at || dossier.en_instruction_at || dossier.en_construction_at || dossier.champs.last.updated_at || nil
|
||||
dossier.update_column(:updated_at, fixed_updated_at)
|
||||
|
||||
progress.inc
|
||||
end
|
||||
progress.finish
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
require Rails.root.join("lib", "tasks", "task_helper")
|
||||
|
||||
namespace :tmp_set_dossiers_last_updated_at do
|
||||
desc 'set for all dossiers last_updated_at'
|
||||
task run: :environment do
|
||||
start_id = ENV.fetch('DOSSIER_START_AT', 0)
|
||||
|
||||
all_dossiers = Dossier.with_discarded
|
||||
.where('dossiers.id > ?', start_id)
|
||||
.includes(:champs, :avis, :commentaires)
|
||||
.order(:id)
|
||||
|
||||
progress = ProgressReport.new(all_dossiers.count)
|
||||
|
||||
all_dossiers.in_batches do |dossiers|
|
||||
dossiers.each do |dossier|
|
||||
last_commentaire_updated_at = dossier.commentaires
|
||||
.where.not(email: OLD_CONTACT_EMAIL)
|
||||
.where.not(email: CONTACT_EMAIL)
|
||||
.maximum(:updated_at)
|
||||
last_avis_updated_at = dossier.avis.maximum(:updated_at)
|
||||
last_champ_updated_at = dossier.champs.maximum(:updated_at)
|
||||
last_champ_private_updated_at = dossier.champs_private.maximum(:updated_at)
|
||||
dossier.update_columns(
|
||||
last_commentaire_updated_at: last_commentaire_updated_at,
|
||||
last_avis_updated_at: last_avis_updated_at,
|
||||
last_champ_updated_at: last_champ_updated_at,
|
||||
last_champ_private_updated_at: last_champ_private_updated_at
|
||||
)
|
||||
progress.inc
|
||||
end
|
||||
rake_puts "dossiers lastid: #{dossiers.last.id}"
|
||||
end
|
||||
|
||||
progress.finish
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
describe '2019_06_06_fix_timestamps_of_migrated_dossiers' do
|
||||
let(:affected_procedure) { create(:simple_procedure, id: 500) }
|
||||
let(:procedure_outside_range) { create(:simple_procedure, id: 5000) }
|
||||
|
||||
let(:affected_dossier) { create(:dossier, procedure: affected_procedure) }
|
||||
let(:dossier_outside_time_range) { create(:dossier, procedure: affected_procedure) }
|
||||
let(:dossier_outside_procedure_range) { create(:dossier, procedure: procedure_outside_range) }
|
||||
|
||||
let(:creation_time) { Time.utc(2017, 1, 1, 12, 0) }
|
||||
let(:en_construction_time) { Time.utc(2018, 1, 1, 12, 0) }
|
||||
let(:pj_migration_time) { Time.utc(2019, 6, 4, 12, 0) }
|
||||
|
||||
let(:rake_task) { Rake::Task['fix_timestamps_of_migrated_dossiers:run'] }
|
||||
|
||||
before do
|
||||
Timecop.freeze(creation_time) do
|
||||
affected_dossier
|
||||
dossier_outside_time_range
|
||||
dossier_outside_procedure_range
|
||||
end
|
||||
Timecop.freeze(en_construction_time) do
|
||||
affected_dossier.update_column(:en_construction_at, Time.zone.now)
|
||||
end
|
||||
Timecop.freeze(pj_migration_time.prev_week) do
|
||||
dossier_outside_time_range.tap(&:touch).reload
|
||||
end
|
||||
Timecop.freeze(pj_migration_time) do
|
||||
dossier_outside_procedure_range.tap(&:touch).reload
|
||||
affected_dossier.tap(&:touch).reload
|
||||
end
|
||||
|
||||
rake_task.invoke
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
it 'fix the updated_at of affected dossiers' do
|
||||
expect(affected_dossier.reload.updated_at).to eq(en_construction_time)
|
||||
end
|
||||
|
||||
it 'ignores dossiers with a procedure_id outside of the procedure range' do
|
||||
expect(dossier_outside_procedure_range.reload.updated_at).to eq(pj_migration_time)
|
||||
end
|
||||
|
||||
it 'ignores dossiers with an updated_at outside of the time range' do
|
||||
expect(dossier_outside_time_range.reload.updated_at).to eq(pj_migration_time.prev_week)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue