Class: AuditFixityCheckJob

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

Instance Method Summary collapse

Instance Method Details

#perform(package:, user:, audit:, **kwargs) ⇒ Object


8
9
10
11
12
13
14
# File 'app/jobs/audit_fixity_check_job.rb', line 8

def perform(package:, user:, audit:, **kwargs)
  @package = package
  @user = user
  @audit = audit

  save_event(*validate_bag(**kwargs))
end

#save_event(outcome, detail) ⇒ Object


35
36
37
38
39
40
41
42
43
44
# File 'app/jobs/audit_fixity_check_job.rb', line 35

def save_event(outcome, detail)
  Event.create(
    package: package,
    user: user,
    audit: audit,
    event_type: "fixity check",
    outcome: outcome,
    detail: detail
  )
end

#validate_bag(storage: Services.storage, bag: storage.new(package.storage_location), mailer: AuditMailer) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/jobs/audit_fixity_check_job.rb', line 16

def validate_bag(storage: Services.storage, bag: storage.new(package.storage_location), mailer: AuditMailer)
  begin
    if bag.valid?
      outcome = "success"
      detail = nil
    else
      outcome = "failure"
      detail = bag.errors.full_messages.join("\n")
      mailer.failure(emails: [audit.user.email], package: package, error: detail).deliver_now
    end
  rescue RuntimeError => e
    outcome = "failure"
    detail = e.to_s
    mailer.failure(emails: [audit.user.email], package: package, error: detail).deliver_now
  end

  [outcome, detail]
end