Class: CreateDerivativesJob

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
CurationConcerns::Lockable
Defined in:
app/jobs/create_derivatives_job.rb

Instance Method Summary collapse

Methods included from CurationConcerns::Lockable

#acquire_lock_for, #lock_manager

Instance Method Details

#parent_needs_reindex?(file_set) ⇒ Boolean

If this file_set is the thumbnail for the parent work, then the parent also needs to be reindexed.

Returns:

  • (Boolean)


26
27
28
29
# File 'app/jobs/create_derivatives_job.rb', line 26

def parent_needs_reindex?(file_set)
  return false unless file_set.parent
  file_set.parent.thumbnail_id == file_set.id
end

#perform(file_set, file_id, filepath = nil) ⇒ Object

Parameters:

  • file_set (FileSet)
  • file_id (String)

    identifier for a Hydra::PCDM::File

  • filepath (String, NilClass) (defaults to: nil)

    the cached file within the CurationConcerns.config.working_path



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/jobs/create_derivatives_job.rb', line 9

def perform(file_set, file_id, filepath = nil)
  return if file_set.video? && !CurationConcerns.config.enable_ffmpeg
  filename = CurationConcerns::WorkingDirectory.find_or_retrieve(file_id, file_set.id, filepath)

  # Prevent other jobs from trying to modify the FileSet at the same time
  acquire_lock_for(file_set.id) do
    file_set.create_derivatives(filename)

    # Reload from Fedora and reindex for thumbnail and extracted text
    file_set.reload
    file_set.update_index
    file_set.parent.update_index if parent_needs_reindex?(file_set)
  end
end