Skip to content

Commit

Permalink
Adapt PJ migration to S3 instead of open stack
Browse files Browse the repository at this point in the history
  • Loading branch information
maatinito committed Oct 25, 2023
1 parent 6aa0126 commit 033cc67
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions app/jobs/pjs_migration_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 033cc67

Please sign in to comment.