Merge pull request #9857 from demarches-simplifiees/remove_now_obsolete_pj_migration_jobs

Tech: suppression du cron et de la tache de migration des pjs vers des buckets dédiés.
This commit is contained in:
LeSim 2023-12-14 15:00:52 +00:00 committed by GitHub
commit 99d2ad3522
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 69 deletions

View file

@ -1,26 +0,0 @@
class Cron::PjsMigrationCronJob < Cron::CronJob
self.schedule_expression = "every 15 minutes"
def perform(*args)
# avoid reschedule enqueued jobs
# but ignore fail jobs
return if migration_jobs.count > 100
blobs = ActiveStorage::Blob
.where.not("key LIKE '%/%'")
.limit(200_000)
blobs.in_batches { |batch| batch.ids.each { |id| PjsMigrationJob.perform_later(id) } }
end
def self.schedulable?
ENV.fetch("MIGRATE_PJS", "enabled") == "enabled"
end
private
def migration_jobs
Delayed::Job
.where(queue: 'pj_migration_jobs')
end
end

View file

@ -1,43 +0,0 @@
require 'fog/openstack'
class PjsMigrationJob < ApplicationJob
queue_as :pj_migration_jobs
def perform(blob_id)
blob = ActiveStorage::Blob.find(blob_id)
return if already_moved?(blob)
service = blob.service
container = service.container
old_key = blob.key
new_key = "#{blob.created_at.strftime('%Y/%m/%d')}/#{old_key[0..1]}/#{old_key}"
excon_response = client.copy_object(container,
old_key,
container,
new_key,
{ "Content-Type" => blob.content_type })
if excon_response.status == 201
blob.update_columns(key: new_key)
client.delete_object(container, old_key)
end
rescue Fog::OpenStack::Storage::NotFound
blob.attachments.destroy_all
end
def already_moved?(blob)
blob.key.include?('/')
end
private
def client
@client ||= begin
credentials = Rails.application.config.active_storage
.service_configurations['openstack']['credentials']
Fog::OpenStack::Storage.new(credentials)
end
end
end