• 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

24.39
/marc_to_solr/lib/solr_deleter.rb
1
require 'net/http'
1✔
2
require 'json'
1✔
3

4
# This class allow us to delete Solr records with our current
5
# version of Traject. Once we upgrade to Traject version 3.1
6
# or later we could use Traject's native delete feature
7
# (see https://github.com/traject/traject/commit/c731d09c6cb15fbe572e4a294a7a127b525b7277)
8
# but keep in mind that Traject's implementation is still in experimental mode
9
# and it does not (yet) support batches.
10
class SolrDeleter
1✔
11
  def initialize(solr_url, logger = nil)
1✔
UNCOV
12
    @solr_url = solr_url
×
UNCOV
13
    @logger = logger
×
14
  end
15

16
  def delete(ids, batch_size = 100)
1✔
UNCOV
17
    ids.each_slice(batch_size) do |batch|
×
UNCOV
18
      delete_batch(batch)
×
19
    end
20
  end
21

22
  private
1✔
23

24
    # content_type = "text/xml"
25
    # request payload is XML (even if the response is in JSON via the wt=json param)
26
    def request_deletion(uri:, body:, content_type: 'text/xml')
1✔
UNCOV
27
      @logger&.info "Deleting #{body}"
×
UNCOV
28
      start_time = Time.now
×
UNCOV
29
      response = Faraday.post(uri) do |req|
×
UNCOV
30
        req.headers = { 'Content-Type' => content_type }
×
UNCOV
31
        req.body = body
×
UNCOV
32
        req.options.open_timeout = 60
×
UNCOV
33
        req.options.read_timeout = 60
×
UNCOV
34
        req.options.write_timeout = 60
×
35
      end
UNCOV
36
      @logger&.info("Delete completed in #{Time.now - start_time} seconds. URL: #{uri}")
×
UNCOV
37
      response
×
38
    rescue Faraday::TimeoutError
UNCOV
39
      @logger&.warn("Delete timed out after #{Time.now - start_time} seconds. URL: #{uri} : #{body}")
×
UNCOV
40
      nil
×
41
    end
42

43
    def build_request_body(ids:)
1✔
UNCOV
44
      output = ['<delete>']
×
UNCOV
45
      ids.each do |id|
×
UNCOV
46
        output << "<id>#{id}</id>"
×
47
      end
48

UNCOV
49
      output << '</delete>'
×
UNCOV
50
      output.join
×
51
    end
52

53
    def valid_response?(response)
1✔
UNCOV
54
      return false if response.nil?
×
55

UNCOV
56
      response.status == 200
×
57
    end
58

59
    def delete_batch(batch)
1✔
UNCOV
60
      uri = "#{@solr_url}/update?waitSearcher=false&wt=json"
×
UNCOV
61
      body = build_request_body(ids: batch)
×
62

UNCOV
63
      response = request_deletion(uri:, body:)
×
UNCOV
64
      return if valid_response?(response)
×
65

66
      # Only retry once
UNCOV
67
      retry_response = request_deletion(uri:, body:)
×
UNCOV
68
      return if valid_response?(retry_response)
×
69

UNCOV
70
      unless retry_response.nil?
×
UNCOV
71
        Honeybadger.notify("Error deleting Solr documents. IDs: #{batch.join(', ')}. Status: #{retry_response.status}. Body: #{retry_response.body}")
×
72
      end
73
    end
74
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