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

pulibrary / bibdata / 1dcebae2-3318-4e77-bc53-82276e293354

02 May 2025 04:45PM UTC coverage: 28.256% (-63.9%) from 92.189%
1dcebae2-3318-4e77-bc53-82276e293354

push

circleci

sandbergja
Add basic infrastructure for compiling rust code

* Add a rake compile task to compile
* Run the rake task in CI
* Run the rake task before rspec tests with the rust tag, to provide quick feedback on rust changes in TDD cycles

2 of 7 new or added lines in 2 files covered. (28.57%)

2467 existing lines in 97 files now uncovered.

1089 of 3854 relevant lines covered (28.26%)

0.29 hits per line

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

40.85
/app/services/numismatics_indexer.rb
1
require 'open-uri'
1✔
2

3
class NumismaticsIndexer
1✔
4
  def self.full_index(solr_url:, progressbar: false, logger: Logger.new(STDERR))
1✔
UNCOV
5
    new(solr_connection: RSolr.connect(url: solr_url), progressbar:, logger:).full_index
×
6
  end
7

8
  attr_reader :solr_connection, :progressbar, :logger
1✔
9

10
  def initialize(solr_connection:, progressbar:, logger:)
1✔
UNCOV
11
    @solr_connection = solr_connection
×
UNCOV
12
    @progressbar = progressbar
×
UNCOV
13
    @logger = logger
×
14
  end
15

16
  def full_index
1✔
UNCOV
17
    solr_documents.each_slice(500) do |docs|
×
UNCOV
18
      index_in_chunks(docs)
×
19
    end
20
    # soft commit to avoid timeouts
UNCOV
21
    solr_connection.commit(commit_attributes: { waitSearcher: false })
×
22
  end
23

24
  def index_in_chunks(docs)
1✔
UNCOV
25
    solr_connection.add(docs)
×
26
  rescue RSolr::Error::Http => e
UNCOV
27
    logger.warn("Failed to index batch, retrying individually, error was: #{e.class}: #{e.message.strip}")
×
UNCOV
28
    index_individually(docs)
×
29
  end
30

31
  # index a batch of records one at a time, logging and continuing on error
32
  def index_individually(docs)
1✔
UNCOV
33
    docs.each do |doc|
×
UNCOV
34
      solr_connection.add(doc)
×
35
    rescue RSolr::Error::Http => e
UNCOV
36
      logger.warn("Failed to index individual record #{doc['id']}, error was: #{e.class}: #{e.message.strip}")
×
37
    end
38
  end
39

40
  def solr_documents
1✔
UNCOV
41
    json_response = PaginatingJsonResponse.new(url: search_url, logger:)
×
UNCOV
42
    pb = progressbar ? ProgressBar.create(total: json_response.total, format: '%a %e %P% Processed: %c from %C') : nil
×
UNCOV
43
    json_response.lazy.map do |json_record|
×
UNCOV
44
      pb&.increment
×
UNCOV
45
      json_record
×
46
    end
47
  end
48

49
  class NumismaticRecordPathBuilder
1✔
50
    attr_reader :result
1✔
51

52
    def initialize(result)
1✔
UNCOV
53
      @result = result
×
54
    end
55

56
    def path
1✔
UNCOV
57
      "#{MARC_LIBERATION_CONFIG['figgy_base_url']}/concern/numismatics/coins/#{id}/orangelight"
×
58
    end
59

60
    def id
1✔
UNCOV
61
      result['id']
×
62
    end
63
  end
64

65
  class PaginatingJsonResponse
1✔
66
    include Enumerable
1✔
67
    attr_reader :url, :logger
1✔
68

69
    def initialize(url:, logger:)
1✔
UNCOV
70
      @url = url
×
UNCOV
71
      @logger = logger
×
72
    end
73

74
    def each
1✔
UNCOV
75
      response = Response.new(url:, page: 1)
×
UNCOV
76
      loop do
×
UNCOV
77
        response.docs.each do |doc|
×
UNCOV
78
          json = json_for(doc)
×
UNCOV
79
          yield json if json
×
80
        end
UNCOV
81
        break unless (response = response.next_page)
×
82
      end
83
    end
84

85
    def json_for(doc)
1✔
UNCOV
86
      path = NumismaticRecordPathBuilder.new(doc).path
×
UNCOV
87
      JSON.parse(URI(path).open.read)
×
88
    rescue StandardError => e
UNCOV
89
      logger.warn("Failed to retrieve numismatics document from #{path}, error was: #{e.class}: #{e.message}")
×
UNCOV
90
      nil
×
91
    end
92

93
    def total
1✔
UNCOV
94
      @total ||= Response.new(url:, page: 1).total_count
×
95
    end
96

97
    class Response
1✔
98
      attr_reader :url, :page
1✔
99

100
      def initialize(url:, page:)
1✔
UNCOV
101
        @url = url
×
UNCOV
102
        @page = page
×
103
      end
104

105
      def docs
1✔
UNCOV
106
        response['data']
×
107
      end
108

109
      def response
1✔
UNCOV
110
        @response ||= JSON.parse(URI("#{url}&page=#{page}").open.read.force_encoding('UTF-8'))
×
111
      end
112

113
      def next_page
1✔
UNCOV
114
        return nil unless response['meta']['pages']['next_page']
×
115

UNCOV
116
        Response.new(url:, page: response['meta']['pages']['next_page'])
×
117
      end
118

119
      def total_count
1✔
UNCOV
120
        response['meta']['pages']['total_count']
×
121
      end
122
    end
123
  end
124

125
  def search_url
1✔
UNCOV
126
    "#{MARC_LIBERATION_CONFIG['figgy_base_url']}/catalog.json?f%5Bhuman_readable_type_ssim%5D%5B%5D=Coin&f%5Bstate_ssim%5D%5B%5D=complete&f%5Bvisibility_ssim%5D%5B%5D=open&per_page=100&q="
×
127
  end
128
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