From a2ae44fa61bdc7ec8ea8311526c41e46bad138ce Mon Sep 17 00:00:00 2001 From: Christian Lautier <15379878+maatinito@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:08:53 -1000 Subject: [PATCH] Adapt PJ migration to S3 instead of open stack --- app/jobs/pjs_migration_job.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/jobs/pjs_migration_job.rb b/app/jobs/pjs_migration_job.rb index 52628685dea..d14a600b437 100644 --- a/app/jobs/pjs_migration_job.rb +++ b/app/jobs/pjs_migration_job.rb @@ -5,23 +5,20 @@ def perform(blob_id) blob = ActiveStorage::Blob.find(blob_id) return if already_moved?(blob) + return if blob.service_name != "s3" service = blob.service - client = service.client - container = service.container + client = service.client.client + container = service.bucket.name 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 + client.copy_object({ bucket: container, copy_source: "#{container}/#{old_key}", key: new_key }) + if service.bucket.object(new_key).exists? blob.update_columns(key: new_key) - client.delete_object(container, old_key) + client.delete_object({ bucket: container, key: old_key }) end + rescue Aws::S3::Errors::ServiceError end def already_moved?(blob)