Class: WorkPreservationAuditService

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

Overview

A service to create and store the preservation data for a given work. Currently it assumes this data will be stored in an AWS S3 bucket accessible with our AWS credentials. This preservation bucket is configured in our s3.yml file and we store it in a different availability region to make sure the data is properly distributed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date: Time.zone.yesterday) ⇒ WorkPreservationAuditService

Returns a new instance of WorkPreservationAuditService.

Parameters:

  • date (defaults to: Time.zone.yesterday)

    date works were approved to audit.



14
15
16
# File 'app/services/work_preservation_audit_service.rb', line 14

def initialize(date: Time.zone.yesterday)
  @date = date
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



11
12
13
# File 'app/services/work_preservation_audit_service.rb', line 11

def date
  @date
end

Instance Method Details

#audit!Boolean

Audits all works approved on the date and validates that their directory exists in preservation

Returns:

  • (Boolean)

    true if all works from the date were present in preservation



20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/work_preservation_audit_service.rb', line 20

def audit!
  works = list_works
  work_status_list = works.map { |work| check_work(work) }
  empty_works = work_status_list.select { |work_status| work_status[:empty] }.pluck(:work)

  if empty_works.count > 0
    raise WorkAuditError, error_message(empty_works)
  end

  true
end