• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 83592e18-0793-497c-89bb-3132924fbfbd

11 Apr 2025 04:14PM UTC coverage: 95.397% (-0.002%) from 95.399%
83592e18-0793-497c-89bb-3132924fbfbd

Pull #2097

circleci

carolyncole
Etracting the S3 File Move into a service so it can be utilize in other processes
Pull Request #2097: Extracting the S3 File Move into a service so it can be utilize in other processes

38 of 39 new or added lines in 4 files covered. (97.44%)

1 existing line in 1 file now uncovered.

3482 of 3650 relevant lines covered (95.4%)

199.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/app/jobs/approved_file_move_job.rb
1
# frozen_string_literal: true
2
class ApprovedFileMoveJob < ApplicationJob
2✔
3
  queue_as :default
2✔
4
  retry_on ActiveRecord::RecordNotFound
2✔
5

6
  def perform(work_id:, source_bucket:, source_key:, target_bucket:, target_key:, size:, snapshot_id:)
2✔
7
    @work_id = work_id
20✔
8
    @snapshot_id = snapshot_id
20✔
9
    @source_bucket = source_bucket
20✔
10
    @source_key = source_key
20✔
11

12
    move_service = S3MoveService.new(work_id:, source_bucket:, source_key:, target_bucket:, target_key:, size:)
20✔
13

14
    etag = move_service.move # if there is an error and exception is raised
20✔
15

16
    snapshot.with_lock do
14✔
17
      snapshot.reload
12✔
18
      snapshot.mark_complete(target_key, etag)
12✔
19
    end
20

21
    # Once the last file has been deleted...
22
    if service.client_s3_files(reload: true, bucket_name: source_bucket).count == 0
12✔
23
      # delete the source directory...
24
      service.delete_s3_object(work.s3_object_key, bucket: source_bucket)
6✔
25

26
      # ...and create the preservation files
27
      work_preservation.preserve!
6✔
28
    end
29
  end
30

31
  def key
2✔
UNCOV
32
    @key ||= "/#{@source_bucket}/#{@source_key}"
×
33
  end
34

35
  def work
2✔
36
    @work ||= Work.find(@work_id)
30✔
37
  end
38

39
  def service
2✔
40
    @service ||= S3QueryService.new(work, "postcuration")
18✔
41
  end
42

43
  def snapshot
2✔
44
    @snapshot ||= ApprovedUploadSnapshot.find(@snapshot_id)
38✔
45
  end
46

47
  def work_path
2✔
48
    @work_path ||= "#{work.doi}/#{work.id}"
6✔
49
  end
50

51
  def work_preservation
2✔
52
    @work_preservation ||= WorkPreservationService.new(work_id: @work_id, path: work_path)
6✔
53
  end
54
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc