Class: DspaceFileCopyJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/dspace_file_copy_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(s3_file_json:, work_id:, migration_snapshot_id:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/dspace_file_copy_job.rb', line 5

def perform(s3_file_json:, work_id:, migration_snapshot_id:)
  s3_file = JSON.parse(s3_file_json)
  work = Work.find(work_id)
  new_key = s3_file["filename_display"]
  s3_key = s3_file["filename"]
  s3_size = s3_file["size"]
  resp = work.s3_query_service.copy_file(source_key: "#{dspace_bucket_name}/#{s3_key}",
                                         target_bucket: work.s3_query_service.bucket_name,
                                         target_key: new_key, size: s3_size)
  unless resp.successful?
    raise "Error copying #{s3_key} to work #{work_id} Response #{resp}"
  end
  if s3_size > 0 # All directories are not part of the migration snapshot
    update_migration(migration_snapshot_id, new_key, s3_size, work)
  end
end