Class: Hyrax::FileSetFixityCheckService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/file_set_fixity_check_service.rb

Overview

This class runs fixity checks on a FileSetBehavior, potentially on multiple files each with multiple versions in the FileSet.

The fixity check itself is performed by FixityCheckJob, which just uses the fedora service to ask for fixity verification. The outcome will be some created ChecksumAuditLog (ActiveRecord) objects, recording the checks and their results.

By default this runs the checks async using ActiveJob, so returns no useful info – the checks are still going Use ChecksumAuditLog.latest_for_file_set_id to retrieve the latest machine-readable checks.

But if you initialize with async_jobs: false, checks will be done blocking in foreground, and you can get back the ChecksumAuditLog records created.

It will only run fixity checks if there are not recent ChecksumAuditLogs on record. “recent” is defined by max_days_between_fixity_checks arg, which defaults to configured Configuration#max_days_between_fixity_checks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set, async_jobs: true, max_days_between_fixity_checks: Hyrax.config.max_days_between_fixity_checks, latest_version_only: false) ⇒ FileSetFixityCheckService

Returns a new instance of FileSetFixityCheckService.

Parameters:

  • file_set (ActiveFedora::Base, String)

    file_set

  • async_jobs (Boolean) (defaults to: true)

    Run actual fixity checks in background. Default true.

  • max_days_between_fixity_checks (int) (defaults to: Hyrax.config.max_days_between_fixity_checks)

    if an exisitng fixity check is recorded within this window, no new one will be created. Default Configuration#max_days_between_fixity_checks. Set to -1 to force check.

  • latest_version_only (Booelan) (defaults to: false)

    . Check only latest version instead of all versions. Default false.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 37

def initialize(file_set,
               async_jobs: true,
               max_days_between_fixity_checks: Hyrax.config.max_days_between_fixity_checks,
               latest_version_only: false)
  @max_days_between_fixity_checks = max_days_between_fixity_checks || 0
  @async_jobs = async_jobs
  @latest_version_only = latest_version_only
  if file_set.is_a?(String)
    @id = file_set
  else
    @id = file_set.id
    @file_set = file_set
  end
end

Instance Attribute Details

#async_jobsObject (readonly)

Returns the value of attribute async_jobs.



26
27
28
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 26

def async_jobs
  @async_jobs
end

#idObject (readonly)

Returns the value of attribute id.



26
27
28
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 26

def id
  @id
end

#latest_version_onlyObject (readonly)

Returns the value of attribute latest_version_only.



26
27
28
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 26

def latest_version_only
  @latest_version_only
end

#max_days_between_fixity_checksObject (readonly)

Returns the value of attribute max_days_between_fixity_checks.



26
27
28
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 26

def max_days_between_fixity_checks
  @max_days_between_fixity_checks
end

Instance Method Details

#fixity_checkObject

Fixity checks each version of each file if it hasn’t been checked recently If object async_jobs is false, will returns the set of most recent fixity check status for each version of the content file(s). As a hash keyed by file_id, values arrays of possibly multiple version checks.

If async_jobs is true (default), just returns nil, stuff is still going on.



58
59
60
61
62
63
64
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 58

def fixity_check
  results = file_set.files.collect { |f| fixity_check_file(f) }

  return if async_jobs

  results.flatten.group_by(&:file_id)
end