Skip to content

Commit bf9e13b

Browse files
committed
Extracting method to ease future switching logic
In discussion with @no_reply, in addressing #4195, we want to explore the following path: 1) As early as possible in the request cycle, create a Hyrax::UploadedFile for both a CarrierWave file or a file selected for upload by BrowseEverything. 2) Building on step 1, we would then hope to reduce branching logic in the request cycle, and preserve existing class interfaces. By making this non-breaking change, I'm orienting the code to deliver on this aspirational goal. Next steps would be: 1) Update the Hyrax::WorksControllerBehavior to create Hyrax::UploadedFile records for the files selected from BrowseEverything (note CarrierWave handles the "inline" uploads). 2) Adjust the extracted `Hyrax::UploadedFile#perform_ingest_later` method to handle files that were created from BrowseEverything. The plan is to add a field to the UploadedFile (perhaps `url_of_file_to_ingest`) that the Hyrax::WorksControllerBehavior would populate based on user input parameters. With that in place, we could look at backporting the solution into the ActorStack.
1 parent 04f257a commit bf9e13b

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

app/models/hyrax/uploaded_file.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,26 @@ def add_file_set!(file_set)
2828
end
2929
update!(file_set_uri: uri)
3030
end
31+
32+
##
33+
# Schedule an IngestJob for this file and the given file_set.
34+
#
35+
# @note This was extracted from the Hyrax::WorkUploadsHandler
36+
# class. The aspirational goal is a multi-step consideration:
37+
#
38+
# - Reduce branching logic in the controller
39+
# - Reduce duplication of transaction steps
40+
#
41+
# @note This may only be applicable for a Valkyrie resource
42+
#
43+
# @todo Refactor to handle both an uploaded_file (current
44+
# behavior) and handle a file assigned via BrowseEverything.
45+
#
46+
# @param file_set [FileSet]
47+
# @return [void]
48+
def perform_ingest_later(file_set:)
49+
wrapper = JobIoWrapper.create_with_varied_file_handling!(user: user, file: self, relation: :original_file, file_set: file_set)
50+
IngestJob.perform_later(wrapper)
51+
end
3152
end
3253
end

app/services/hyrax/work_uploads_handler.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ def make_file_set_and_ingest(file)
114114
file_set.permission_manager.acl.save if file_set.permission_manager.acl.pending_changes?
115115
append_to_work(file_set)
116116

117-
IngestJob.perform_later(wrap_file(file, file_set))
117+
file.perform_ingest_later(file_set: file_set)
118118
Hyrax.publisher.publish('object.metadata.updated', object: file_set, user: file.user)
119+
119120
{ file_set: file_set, user: file.user }
120121
end
121122

@@ -160,13 +161,6 @@ def target_permissions
160161
@target_permissions ||= Hyrax::AccessControlList.new(resource: work)
161162
end
162163

163-
##
164-
# @api private
165-
# @return [JobIoWrapper]
166-
def wrap_file(file, file_set)
167-
JobIoWrapper.create_with_varied_file_handling!(user: file.user, file: file, relation: :original_file, file_set: file_set)
168-
end
169-
170164
##
171165
# @api private
172166
#

spec/models/hyrax/uploaded_file_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@
88
temp_dir = Rails.root + 'tmp'
99
expect(subject.file.path).to start_with temp_dir.to_s
1010
end
11+
12+
describe '#perform_ingest_later' do
13+
let(:user) { FactoryBot.create(:user) }
14+
subject { described_class.create(file: file1, user: user) }
15+
context 'for a Valkyrie object' do
16+
it "schedules an IngestJob" do
17+
file_set = FactoryBot.valkyrie_create(:hyrax_file_set)
18+
expect(IngestJob).to receive(:perform_later).with(kind_of(JobIoWrapper))
19+
subject.perform_ingest_later(file_set: file_set)
20+
end
21+
end
22+
end
1123
end

0 commit comments

Comments
 (0)