Sha256: b1b9a0159c5f617e919cd51708c62de5db2e368bccdb547e1b28b34873d637d7

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true
class ValkyrieCreateDerivativesJob < Hyrax::ApplicationJob
  queue_as Hyrax.config.ingest_queue_name
  def perform(file_set_id, file_id, _filepath = nil)
    file_metadata = Hyrax.custom_queries.find_file_metadata_by(id: file_id)
    return if file_metadata.video? && !Hyrax.config.enable_ffmpeg
    # Get file into a local path.
    file = Hyrax.storage_adapter.find_by(id: file_metadata.file_identifier)
    # Call derivatives with the file_set.
    derivative_service = Hyrax::DerivativeService.for(file_metadata)
    derivative_service.create_derivatives(file.disk_path)
    reindex_parent(file_set_id)
  end

  private

  def reindex_parent(file_set_id)
    file_set = Hyrax.query_service.find_by(id: file_set_id)
    parent = Hyrax.custom_queries.find_parent_work(resource: file_set)
    return unless parent.thumbnail_id == file_set.id
    Hyrax.logger.debug { "Reindexing #{parent.id} due to creation of thumbnail derivatives." }
    Hyrax.index_adapter.save(resource: parent)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/jobs/valkyrie_create_derivatives_job.rb
hyrax-5.0.0 app/jobs/valkyrie_create_derivatives_job.rb
hyrax-5.0.0.rc3 app/jobs/valkyrie_create_derivatives_job.rb
hyrax-5.0.0.rc2 app/jobs/valkyrie_create_derivatives_job.rb
hyrax-5.0.0.rc1 app/jobs/valkyrie_create_derivatives_job.rb