Class: FixityCheckJob

Inherits:
Hyrax::ApplicationJob show all
Defined in:
app/jobs/fixity_check_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(uri, file_set_id:, file_id:) ⇒ Object

A Job class that runs a fixity check (using Hyrax.config.fixity_service) which contacts fedora and requests a fixity check), and stores the results in an ActiveRecord ChecksumAuditLog row. It also prunes old ChecksumAuditLog rows after creating a new one, to keep old ones you don’t care about from filling up your db.

The uri passed in is a fedora URI that fedora can run fixity check on. It’s normally a version URI like:

http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content/fcr:versions/version1

But could theoretically be any URI fedora can fixity check on, like a file uri:

http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content

The file_set_id and file_id are used only for logging context in the ChecksumAuditLog, and determining what old ChecksumAuditLogs can be pruned.

If calling async as a background job, return value is irrelevant, but if calling sync with ‘perform_now`, returns the ChecksumAuditLog record recording the check.

Parameters:

  • uri (String)

    uri - of the specific file/version to fixity check

  • file_set_id (FileSet)

    the id for FileSet parent object of URI being checked.

  • file_id (String)

    File#id, used for logging/reporting.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/jobs/fixity_check_job.rb', line 27

def perform(uri, file_set_id:, file_id:)
  run_check(file_set_id, file_id, uri).tap do |audit|
    result   = audit.failed? ? :failure : :success
    file_set = ::FileSet.find(file_set_id)

    Hyrax.publisher.publish('file.set.audited', file_set: file_set, audit_log: audit, result: result)

    # @todo remove this callback call for Hyrax 4.0.0
    if audit.failed? && Hyrax.config.callback.set?(:after_fixity_check_failure)
      Hyrax.config.callback.run(:after_fixity_check_failure,
                                file_set,
                                checksum_audit_log: audit, warn: false)
    end
  end
end