Sha256: 80c3be2b57cff85e239c00bfb94e3841de2e48fa13b32de13cb01c50e4638e82

Contents?: true

Size: 1.66 KB

Versions: 10

Compression:

Stored size: 1.66 KB

Contents

class AuditJob < ActiveFedoraPidBasedJob
  def queue_name
    :audit
  end

  PASS = 'Passing Audit Run'
  FAIL = 'Failing Audit Run'

  attr_accessor :uri, :pid, :path

  # URI of the resource to audit.
  # This URI could include the actual resource (e.g. content) and the version to audit:
  #     http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content/fcr:versions/version1
  # but it could also just be:
  #     http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content
  def initialize(id, path, uri)
    super(uri)
    self.pid = id
    self.path = path
    self.uri = uri
  end

  def run
    fixity_ok = false
    log = run_audit
    fixity_ok = (log.pass == 1)
    unless fixity_ok
      # send the user a message about the failing audit
      login = generic_file.depositor
      user = User.find_by_user_key(login)
      logger.warn "User '#{login}' not found" unless user
      job_user = User.audituser()
      file_title = generic_file.title.first
      message = "The audit run at #{log.created_at} for #{file_title} (#{uri}) failed."
      subject = FAIL
      job_user.send_message(user, message, subject)
    end
    fixity_ok
  end

  protected

    def run_audit
      begin
        fixity_ok = ActiveFedora::FixityService.new(uri).check
      rescue Ldp::NotFound
        error_msg = "resource not found"
      end

      if fixity_ok
        passing = 1
        ChecksumAuditLog.prune_history(pid, path)
      else
        logger.warn "***AUDIT*** Audit failed for #{uri} #{error_msg}"
        passing = 0
      end
      ChecksumAuditLog.create!(pass: passing, pid: pid, version: uri, dsid: path)
    end

    def logger
      ActiveFedora::Base.logger
    end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
sufia-6.0.0.rc4 sufia-models/app/jobs/audit_job.rb
sufia-models-6.0.0.rc4 app/jobs/audit_job.rb
sufia-6.0.0.rc3 sufia-models/app/jobs/audit_job.rb
sufia-models-6.0.0.rc3 app/jobs/audit_job.rb
sufia-6.0.0.rc2 sufia-models/app/jobs/audit_job.rb
sufia-models-6.0.0.rc2 app/jobs/audit_job.rb
sufia-6.0.0.rc1 sufia-models/app/jobs/audit_job.rb
sufia-models-6.0.0.rc1 app/jobs/audit_job.rb
sufia-6.0.0.beta1 sufia-models/app/jobs/audit_job.rb
sufia-models-6.0.0.beta1 app/jobs/audit_job.rb