• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / f04bc944-f9b4-4a42-8b26-dcacd0e3e688

11 Mar 2025 10:27PM UTC coverage: 34.017% (-58.1%) from 92.162%
f04bc944-f9b4-4a42-8b26-dcacd0e3e688

Pull #2653

circleci

christinach
Add new lc_subject_facet field.
Helps with the vocabulary work https://github.com/pulibrary/orangelight/pull/3386
In this new field we index only the lc subject heading and the subdivisions
So that when the user searches using the Details section, they can query solr for
all the subject headings and their divisions.

This is needed for the Subject browse Vocabulary work.
example: "lc_subject_facet": [
             "Booksellers and bookselling—Italy—Directories",
             "Booksellers and bookselling-Italy",
             "Booksellers and bookselling"
              ]
Pull Request #2653: Add new lc_subject_facet field.

1 of 3 new or added lines in 1 file covered. (33.33%)

2215 existing lines in 93 files now uncovered.

1294 of 3804 relevant lines covered (34.02%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.51
/app/services/aws_sqs_poller.rb
1
# This service is intended to be run by a daemon. It watches the AWS SQS poll
2
# for full dump events and kicks off a job to process them.
3
class AwsSqsPoller
1✔
4
  def self.poll
1✔
UNCOV
5
    queue_url = Rails.configuration.alma['sqs_queue_url']
×
UNCOV
6
    poller = Aws::SQS::QueuePoller.new(queue_url)
×
UNCOV
7
    end_polling = false
×
8

9
    # End polling if the process is killed by restarting.
UNCOV
10
    Signal.trap('TERM') do
×
UNCOV
11
      end_polling = true
×
12
    end
13

UNCOV
14
    poller.after_empty_receive do |stats|
×
UNCOV
15
      Rails.logger.info("AWS SQS Poller after_empty_receive request_count: #{stats.request_count}")
×
UNCOV
16
      Rails.logger.info("AWS SQS Poller after_empty_receive received_message_count: #{stats.received_message_count}")
×
UNCOV
17
      Rails.logger.info("AWS SQS Poller after_empty_receive last_message_received_at: #{stats.last_message_received_at}")
×
18
    end
19

UNCOV
20
    poller.before_request do |stats|
×
UNCOV
21
      Rails.logger.info("AWS SQS Poller before_request request_count: #{stats.request_count}")
×
UNCOV
22
      Rails.logger.info("AWS SQS Poller before_request message_count: #{stats.received_message_count}")
×
UNCOV
23
      Rails.logger.info("AWS SQS Poller before_request last_message_received_at: #{stats.last_message_received_at}")
×
UNCOV
24
      throw :stop_polling if end_polling
×
25
    end
26

UNCOV
27
    poller.poll do |msg|
×
UNCOV
28
      Rails.logger.info('Polls message')
×
UNCOV
29
      message_body = JSON.parse(msg[:body])
×
UNCOV
30
      job_name = message_body['job_instance']['name']
×
UNCOV
31
      Rails.logger.info("AWS SQS Poller message_body: #{message_body}")
×
UNCOV
32
      next unless Rails.configuration.alma[:jobs].keys.include?(job_name)
×
33

UNCOV
34
      dump = AlmaDumpFactory.bib_dump(message_body)
×
35
      # running dump creation in the background prevents the queue
36
      # event from timing out and requeuing
UNCOV
37
      Import::Alma.perform_async(
×
38
        dump.id,
39
        message_body['job_instance']['id']
40
      )
41
    rescue AlmaDumpFactory::AlmaDuplicateEventError
UNCOV
42
      Rails.logger.error("Rescue from AlmaDuplicateEventError with alma_process_id: #{message_body['job_instance']['id']}")
×
43
    end
44
  end
45
end
46

47
class AlmaDumpFactory
1✔
48
  attr_reader :message
1✔
49

50
  class AlmaDumpError < StandardError
1✔
51
    attr_reader :alma_message
1✔
52

53
    def initialize(alma_message)
1✔
UNCOV
54
      super
×
UNCOV
55
      @alma_message = alma_message
×
56
    end
57

58
    def message
1✔
UNCOV
59
      status = alma_message['job_instance']['status']['value']
×
UNCOV
60
      "Alma job completed with invalid status. Alma status: #{status}. Job id: #{alma_message['id']}"
×
61
    end
62
  end
63

64
  class AlmaDuplicateEventError < StandardError
1✔
65
  end
66

67
  def initialize(message)
1✔
UNCOV
68
    @message = message
×
69
  end
70

71
  def self.bib_dump(message)
1✔
UNCOV
72
    new(message).bib_dump
×
73
  end
74

75
  def bib_dump
1✔
UNCOV
76
    Dump.create(dump_type:,
×
77
                event: dump_event,
78
                generated_date: dump_event.start)
79
  end
80

81
  def dump_type
1✔
UNCOV
82
    @dump_type ||= Rails.configuration.alma[:jobs][job_name]['dump_type']
×
83
  end
84

85
  def job_name
1✔
UNCOV
86
    message['job_instance']['name']
×
87
  end
88

89
  def alma_job_status
1✔
UNCOV
90
    status = message['job_instance']['status']['value']
×
UNCOV
91
    raise AlmaDumpError, message unless status == 'COMPLETED_SUCCESS'
×
92

UNCOV
93
    status
×
94
  rescue StandardError => e
UNCOV
95
    Rails.logger.error(e.message)
×
UNCOV
96
    Honeybadger.notify(e)
×
UNCOV
97
    status
×
98
  end
99

100
  def dump_event
1✔
UNCOV
101
    @event ||= Event.create!(
×
102
      start: event_start,
103
      finish: event_finish,
104
      success: true,
105
      alma_job_status:,
106
      message_body: message.to_json
107
    )
108
  rescue ActiveRecord::RecordInvalid => e
UNCOV
109
    Rails.logger.error("#{e.message} message_body: #{message.to_json}")
×
UNCOV
110
    raise AlmaDuplicateEventError
×
111
  end
112

113
  def event_start
1✔
UNCOV
114
    message['job_instance']['start_time']
×
115
  end
116

117
  def event_finish
1✔
UNCOV
118
    message['job_instance']['end_time']
×
119
  end
120
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc