Class: Upgrade::FileTypeIterationJob

Inherits:
IterationJob
  • Object
show all
Defined in:
app/jobs/upgrade/file_type_iteration_job.rb

Direct Known Subclasses

BackfillDerivativesBase, FixMimeTypes

Instance Method Summary collapse

Instance Method Details

#apply(modelfile) ⇒ Object

Raises:

  • (NotImplementedError)


6
7
8
# File 'app/jobs/upgrade/file_type_iteration_job.rb', line 6

def apply(modelfile)
  raise NotImplementedError
end

#build_enumerator(cursor:) ⇒ Object



24
25
26
# File 'app/jobs/upgrade/file_type_iteration_job.rb', line 24

def build_enumerator(cursor:)
  enumerator_builder.active_record_on_records(scope, cursor: cursor)
end

#each_iteration(modelfile) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'app/jobs/upgrade/file_type_iteration_job.rb', line 28

def each_iteration(modelfile)
  apply(modelfile)
rescue Errno::EACCES => ex
  Rails.logger.error ex.message
rescue Shrine::FileNotFound
  Rails.logger.error("File not found: #{modelfile.path_within_library}")
rescue Shrine::Error => ex
  Rails.logger.error("File error: #{ex.message} #{modelfile.path_within_library}")
rescue MiniMagick::Error => ex
  Rails.logger.error ex.message
end

#mime_types ⇒ Object

Raises:

  • (NotImplementedError)


2
3
4
# File 'app/jobs/upgrade/file_type_iteration_job.rb', line 2

def mime_types
  raise NotImplementedError
end

#scope ⇒ Object



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

def scope
  mime_type_clause = case DatabaseDetector.server
  when :postgresql
    "json_extract_path_text(attachment_data, 'metadata', 'mime_type') IN (?)"
  when :mysql
    "json_value(attachment_data, '$.metadata.mime_type') IN (?)"
  when :sqlite
    "json_extract(attachment_data, '$.metadata.mime_type') IN (?)"
  else
    raise NotImplementedError.new("Unknown database adapter #{DatabaseDetector.server}")
  end
  ModelFile.unscoped.where(mime_type_clause, mime_types.map(&:to_s))
end