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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

1 of 3 new or added lines in 2 files covered. (33.33%)

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 hits per line

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

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

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

UNCOV
12
    resp = service.copy_file(source_key: key, target_bucket:, target_key:, size:)
×
13

UNCOV
14
    unless resp.successful?
×
UNCOV
15
      raise "Error copying #{key} to #{target_bucket}/#{target_key} Response #{resp.to_json}"
×
16
    end
UNCOV
17
    status = service.check_file(bucket: target_bucket, key: target_key)
×
UNCOV
18
    unless status
×
UNCOV
19
      raise "File check was not valid #{source_key} to #{target_bucket}/#{target_key} Response #{status.to_json}"
×
20
    end
UNCOV
21
    etag = if resp.respond_to? :copy_object_result
×
UNCOV
22
             resp.copy_object_result.etag
×
23
           else
24
             resp.etag
×
25
           end.delete('"')
26

27
    # raise("Failed to resolve the ApprovedUploadSnapshot for #{@snapshot_id}") if snapshot.nil?
28

UNCOV
29
    snapshot.with_lock do
×
UNCOV
30
      snapshot.reload
×
UNCOV
31
      snapshot.mark_complete(target_key, etag)
×
32
    end
UNCOV
33
    service.delete_s3_object(source_key, bucket: source_bucket)
×
34

35
    # Once the last file has been deleted...
UNCOV
36
    if service.client_s3_files(reload: true, bucket_name: source_bucket).count == 0
×
37
      # delete the source directory...
UNCOV
38
      service.delete_s3_object(work.s3_object_key, bucket: source_bucket)
×
39

40
      # ...and create the preservation files
UNCOV
41
      work_preservation.preserve!
×
42
    end
43
  end
44

45
  def key
1✔
UNCOV
46
    @key ||= "/#{@source_bucket}/#{@source_key}"
×
47
  end
48

49
  def work
1✔
UNCOV
50
    @work ||= Work.find(@work_id)
×
51
  end
52

53
  def service
1✔
UNCOV
54
    @service ||= S3QueryService.new(work, "postcuration")
×
55
  end
56

57
  def snapshot
1✔
UNCOV
58
    @snapshot ||= ApprovedUploadSnapshot.find(@snapshot_id)
×
59
  end
60

61
  def work_path
1✔
UNCOV
62
    @work_path ||= "#{work.doi}/#{work.id}"
×
63
  end
64

65
  def work_preservation
1✔
UNCOV
66
    @work_preservation ||= WorkPreservationService.new(work_id: @work_id, path: work_path)
×
67
  end
68
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