Class: WorkEmbargoService

Inherits:
Object
  • Object
show all
Defined in:
app/services/work_embargo_service.rb

Overview

A service to move work data from the post-curation bucket to the embargo bucket for currently embargoed works

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work_id:) ⇒ WorkEmbargoService

Returns a new instance of WorkEmbargoService.

Parameters:

  • work_id (Integer)

    The ID of the work to preserve.



9
10
11
12
13
14
# File 'app/services/work_embargo_service.rb', line 9

def initialize(work_id:)
  @work = Work.find(work_id)
  @source_bucket = PULS3Client.post_curation_config[:bucket]
  @target_bucket = PULS3Client.embargo_config[:bucket]
  @pul_s3_client = S3QueryService.new(work, bucket_name: source_bucket)
end

Instance Attribute Details

#pul_s3_clientObject (readonly)

Returns the value of attribute pul_s3_client.



6
7
8
# File 'app/services/work_embargo_service.rb', line 6

def pul_s3_client
  @pul_s3_client
end

#source_bucketObject (readonly)

Returns the value of attribute source_bucket.



6
7
8
# File 'app/services/work_embargo_service.rb', line 6

def source_bucket
  @source_bucket
end

#target_bucketObject (readonly)

Returns the value of attribute target_bucket.



6
7
8
# File 'app/services/work_embargo_service.rb', line 6

def target_bucket
  @target_bucket
end

#workObject (readonly)

Returns the value of attribute work.



6
7
8
# File 'app/services/work_embargo_service.rb', line 6

def work
  @work
end

Instance Method Details

#move(user:) ⇒ Object

move the files



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/work_embargo_service.rb', line 17

def move(user:)
  files = pul_s3_client.client_s3_files(reload: true, bucket_name: source_bucket)
  snapshot = EmbargoUploadSnapshot.new(work:)
  snapshot.store_files(files, current_user: user)
  snapshot.save
  files.each do |file|
    move_service = S3MoveService.new(work_id: work.id, source_bucket:, source_key: file.key, target_bucket:, target_key: file.key, size: file.size)

    etag = move_service.move # if there is an error and exception is raised

    snapshot.mark_complete(file.key, etag)
  end
  true
end