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

pulibrary / bibdata / 4f01b5ec-96e4-40e5-bb74-6da450726a2e

pending completion
4f01b5ec-96e4-40e5-bb74-6da450726a2e

Pull #2143

circleci

Jane Sandberg
explicitly require redis gem
Pull Request #2143: Bump sidekiq and sidekiq-pro

3555 of 3942 relevant lines covered (90.18%)

307.23 hits per line

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

91.49
/app/models/dump.rb
1
# encoding: utf-8
2
require 'zip'
1✔
3
require 'net/sftp'
1✔
4
require 'date'
1✔
5

6
class Dump < ActiveRecord::Base
1✔
7
  ENQUEUED = 'enqueued'.freeze
1✔
8
  STARTED = 'started'.freeze
1✔
9
  DONE = 'done'.freeze
1✔
10

11
  belongs_to :event
1✔
12
  belongs_to :dump_type
1✔
13
  has_many :dump_files
1✔
14
  # These only apply to change dumps (stored in db rather than text files)
15
  serialize :delete_ids
1✔
16
  serialize :update_ids
1✔
17
  serialize :recap_barcodes
1✔
18

19
  before_destroy do
1✔
20
    self.dump_files.each do |df|
28✔
21
      df.destroy
15✔
22
    end
23
  end
24

25
  scope :partner_recap_full, -> { where(dump_type: DumpType.where(constant: 'PARTNER_RECAP_FULL')) }
1✔
26
  scope :partner_recap, -> { where(dump_type: DumpType.where(constant: 'PARTNER_RECAP')) }
12✔
27
  scope :changed_records, -> { where(dump_type: DumpType.where(constant: 'CHANGED_RECORDS')) }
2✔
28
  scope :full_dumps, -> { where(dump_type: DumpType.where(constant: 'ALL_RECORDS')) }
2✔
29

30
  class << self
1✔
31
    ##
32
    # Create a dump of partner recap incremental records.
33
    def partner_update
1✔
34
      dump = nil
2✔
35
      timestamp = incremental_update_timestamp
2✔
36
      Event.record do |event|
2✔
37
        dump = Dump.create(dump_type: DumpType.find_by(constant: "PARTNER_RECAP"))
2✔
38
        ScsbImportJob.perform_later(dump.id, timestamp)
2✔
39
        dump.event = event
2✔
40
        dump.save
2✔
41
      end
42
      dump
2✔
43
    end
44

45
    def latest_generated
1✔
46
      order('generated_date desc').first
1✔
47
    end
48

49
    private
1✔
50

51
      ##
52
      # Figure out when was the last time we got partner update records, and find
53
      # anything that has appeared since then. The ways we can know the last time
54
      # we got partner update records are:
55
      # * via an environment variable
56
      # * look for the last partner recap dump and get its creation date
57
      # * or, if neither of those, use yesterday
58
      def incremental_update_timestamp
1✔
59
        (ENV['TIMESTAMP'] || last_incremental_update || DateTime.now - 1).to_time.strftime('%Y-%m-%d %H:%M:%S.%6N %z')
8✔
60
      end
61

62
      def last_incremental_update
1✔
63
        Dump.partner_recap.last&.created_at
9✔
64
      end
65
  end # class << self
66

67
  def full_dump?
1✔
68
    dump_type.constant == 'ALL_RECORDS'
×
69
  end
70

71
  def subsequent_partner_incrementals
1✔
72
    Dump.partner_recap.where(generated_date: generated_date..Float::INFINITY)
1✔
73
  end
74

75
  def enqueued?
1✔
76
    index_status == ENQUEUED
×
77
  end
78

79
  def started?
1✔
80
    index_status == STARTED
×
81
  end
82

83
  def done?
1✔
84
    index_status == DONE
×
85
  end
86
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