diff --git a/app/jobs/pjs_migration_job.rb b/app/jobs/pjs_migration_job.rb index 52628685dea..efa26f4bc81 100644 --- a/app/jobs/pjs_migration_job.rb +++ b/app/jobs/pjs_migration_job.rb @@ -5,23 +5,18 @@ 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 - blob.update_columns(key: new_key) - client.delete_object(container, old_key) - end + client.copy_object({ bucket: container, copy_source: "#{container}/#{old_key}", key: new_key }) + blob.update_columns(key: new_key) + client.delete_object({ bucket: container, key: old_key }) + rescue Aws::S3::Errors::ServiceError end def already_moved?(blob)