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

pulibrary / pdc_describe / a503fa1a-8989-43c9-8895-a216ff8090a2

14 Apr 2025 01:30PM UTC coverage: 95.397% (-0.002%) from 95.399%
a503fa1a-8989-43c9-8895-a216ff8090a2

push

circleci

web-flow
Extracting the S3 File Move into a service so it can be utilized in other processes (#2097)

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%)

398.04 hits per line

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

96.88
/app/services/s3_move_service.rb
1
# frozen_string_literal: true
2

3
class S3MoveService
2✔
4
  attr_reader :source_bucket, :source_key, :target_bucket, :target_key, :size, :service, :copy_source
2✔
5

6
  def initialize(work_id:, source_bucket:, source_key:, target_bucket:, target_key:, size:)
2✔
7
    @copy_source = "/#{source_bucket}/#{source_key}"
20✔
8
    @source_key = source_key
20✔
9
    @source_bucket = source_bucket
20✔
10
    @target_bucket = target_bucket
20✔
11
    @target_key = target_key
20✔
12
    @size = size
20✔
13
    @service = S3QueryService.new(Work.find(work_id), bucket_name: source_bucket)
20✔
14
  end
15

16
  def move
2✔
17
    etag = copy_file # will raise exception if there is an error
20✔
18
    check_file # will raise exception if there is an error
16✔
19
    service.delete_s3_object(source_key, bucket: source_bucket)
10✔
20
    etag
10✔
21
  end
22

23
  private
2✔
24

25
    def copy_file
2✔
26
      resp = service.copy_file(source_key: copy_source, target_bucket:, target_key:, size:)
20✔
27
      unless resp.successful?
18✔
28
        raise "Error copying #{copy_source} to #{target_bucket}/#{target_key} Response #{resp.to_json}"
2✔
29
      end
30
      etag(resp)
16✔
31
    rescue Aws::S3::Errors::NoSuchKey => error
32
      status = service.check_file(bucket: source_bucket, key: source_key)
2✔
33
      unless status
2✔
34
        raise "Missing source file #{copy_source} can not copy to #{target_bucket}/#{target_key} Error: #{error}"
2✔
35
      end
36
    end
37

38
    def check_file
2✔
39
      status = service.check_file(bucket: target_bucket, key: target_key)
16✔
40
      unless status
16✔
41
        raise "File check was not valid #{copy_source} to #{target_bucket}/#{target_key} Response #{status.to_json}"
6✔
42
      end
43
    end
44

45
    def etag(resp)
2✔
46
      if resp.respond_to? :copy_object_result
16✔
47
        resp.copy_object_result.etag
16✔
48
      else
NEW
49
        resp.etag
×
50
      end.delete('"')
51
    end
52
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