s3_migration 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1e5306758296ed3929c545d4607b6e05e439ffb274df1a4bb6f5af23b9ad803
4
- data.tar.gz: 9b0c6999c349179acf6e3da35608510442efdf67863950af29387f5e6f217d8c
3
+ metadata.gz: 3d0c1aad0021835d5ff8465192330a126687faed7599bfbd80b470bc856d3545
4
+ data.tar.gz: 857093deac26f2df2c9deb46c32f42f5cc99fac772bdf892333a2afd170280ca
5
5
  SHA512:
6
- metadata.gz: e74181493a0e761de5be0376a20f4f40dc8916b0bda396e72073b4c3c9463cd04f36443fc7fd635983882d8cff43fdd5b3c61d696fa383ffa3321baf9912b4b3
7
- data.tar.gz: 49aaf2bf5292519ab484b0b44ea2b679a323ba5d99a7b2b28c609fd3af8a7490bbb22cf4e1e36cef62c20554d9c47bf71b90d425ed1848b918185e03c2635f41
6
+ metadata.gz: 29a5c98a1d1fe1f234f2b7b634825ebebe33e4fc67f874122cd442ee18da4296f4b42c32c39ff41a5194b8062bef7d4e7077ffba3c13d8bd1074574274f7cb62
7
+ data.tar.gz: eb01c4628148b16461a2734edb677b1940f41e1427d34bdbd16657dbd0d1c4d6c21ac5714fc7be20a1eb9f563c917bd86b5aa5f5677ad36204b53986e7960970
@@ -99,7 +99,7 @@ module S3Migration
99
99
  end
100
100
 
101
101
  def switch_identifier(uploaded, disk_sha256)
102
- current = Hyrax.query_service.find_by(id: original.id)
102
+ current = S3Migration.find_resource(original.id)
103
103
  unless SourceStorage.handles?(current.file_identifier)
104
104
  return result(:raced, 'already migrated by another process')
105
105
  end
@@ -8,8 +8,8 @@ module S3Migration
8
8
  retry_on StandardError, wait: :polynomially_longer, attempts: 5
9
9
 
10
10
  def perform(file_set_id, dry_run: false)
11
- file_set = Hyrax.query_service.find_by(id: file_set_id)
12
- original = Hyrax.custom_queries.find_original_file(file_set:)
11
+ file_set = S3Migration.find_file_set(file_set_id)
12
+ original = S3Migration.find_original_file(file_set:)
13
13
  return unless original
14
14
 
15
15
  result = S3Migration::FileMigrator.new(file_set:, original:, dry_run:).call
@@ -98,7 +98,7 @@ module S3Migration
98
98
  end
99
99
 
100
100
  def current
101
- @current ||= Hyrax.query_service.find_by(id: entry[:file_metadata_id])
101
+ @current ||= S3Migration.find_resource(entry[:file_metadata_id])
102
102
  end
103
103
 
104
104
  def current_identifier
@@ -26,7 +26,7 @@ module S3Migration
26
26
  end
27
27
 
28
28
  def self.files_for(file_set)
29
- Hyrax.custom_queries.find_files(file_set:)
29
+ S3Migration.find_files(file_set:)
30
30
  rescue Valkyrie::Persistence::ObjectNotFoundError
31
31
  nil
32
32
  end
@@ -26,7 +26,7 @@ module S3Migration
26
26
 
27
27
  # When the database cannot be read, keep the upload: the manifest entry still points at it.
28
28
  def referenced?(upload_id)
29
- Hyrax.query_service.find_by(id: file_metadata_id).file_identifier == upload_id
29
+ S3Migration.find_resource(file_metadata_id).file_identifier == upload_id
30
30
  rescue StandardError
31
31
  true
32
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module S3Migration
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/s3_migration.rb CHANGED
@@ -58,12 +58,41 @@ module S3Migration
58
58
  end
59
59
 
60
60
  def original_for(file_set, on_error: nil)
61
- Hyrax.custom_queries.find_original_file(file_set:)
61
+ find_original_file(file_set:)
62
62
  rescue StandardError => e
63
63
  on_error&.call(file_set, e)
64
64
  nil
65
65
  end
66
66
 
67
+ # The lookups below ask only the non-Wings services. The composite ones also ask Wings, and a miss there
68
+ # reaches Fedora, which can hang (and ActiveFedora may try to create the tenant's base container).
69
+ def find_resource(id)
70
+ each_service_result { |service| service.find_by(id:) }.first || raise(Valkyrie::Persistence::ObjectNotFoundError)
71
+ end
72
+ alias find_file_set find_resource
73
+
74
+ def find_files(file_set:)
75
+ each_service_result { |service| service.custom_queries.find_files(file_set:).to_a }.flatten
76
+ end
77
+
78
+ def find_original_file(file_set:)
79
+ each_service_result { |service| service.custom_queries.find_original_file(file_set:) }.first
80
+ end
81
+
82
+ # Each service's non-nil result; raises ObjectNotFoundError only when every service raised it.
83
+ def each_service_result
84
+ errors = []
85
+ results = query_services.filter_map do |service|
86
+ yield service
87
+ rescue Valkyrie::Persistence::ObjectNotFoundError => e
88
+ errors << e
89
+ nil
90
+ end
91
+ raise errors.first if results.empty? && errors.any?
92
+
93
+ results
94
+ end
95
+
67
96
  def query_services
68
97
  service = Hyrax.query_service
69
98
  services = service.respond_to?(:services) ? service.services : [service]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Kadel