Class: CdmMigrator::BatchCreateFilesWithOrderedMembersJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- CdmMigrator::BatchCreateFilesWithOrderedMembersJob
- Defined in:
- app/jobs/cdm_migrator/batch_create_files_with_ordered_members_job.rb
Instance Method Summary collapse
-
#perform(work, ingest_work, user) ⇒ Object
With this job, the member association is saved once at the very end instead, which can speed up the upload process.
Instance Method Details
#perform(work, ingest_work, user) ⇒ Object
With this job, the member association is saved once
at the very end instead, which can speed up the upload process. This job takes
advantage of the same strategy as Hyrax::Actors::FileSetOrderedMembersActor
but you don't need the OrderedMembersActor constant initialized.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/jobs/cdm_migrator/batch_create_files_with_ordered_members_job.rb', line 17 def perform work, ingest_work, user # Reload the work to get the most recent and accurate member associations work.reload if work.ordered_members.to_a.empty? && work.file_sets.empty? attach_files(work, ingest_work.files, user) else delete_excess_file_sets(work) ordered_count = work.reload.ordered_members.to_a.count unless ordered_count == ingest_work.files.count # Attach any files that might be missing files = ingest_work[ordered_count..] attach_files(work, files, user) end end first_file_set = work.ordered_members.to_a.first work.representative = first_file_set work.thumbnail = first_file_set work.save! work.file_sets.each { |fs| CdmIngestFilesJob.perform_later(fs, fs.import_url, user, ingest_work) } end |