Sha256: 7474d25f4a91fa6c5302b8ec0e240998786509d8ab5b64729daa246288ec5b98

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

module Spotlight
  ##
  # a log entry representing an attempt to reindex some number of records in an exhibit
  class ReindexingLogEntry < ActiveRecord::Base
    enum job_status: { unstarted: 0, in_progress: 1, succeeded: 2, failed: 3 }

    belongs_to :exhibit, class_name: 'Spotlight::Exhibit'
    belongs_to :user, class_name: '::User', optional: true

    # null start times sort to the top, to more easily surface pending reindexing
    default_scope { order(Arel.sql('start_time IS NOT NULL, start_time DESC')) }
    scope :recent, -> { limit(5) }
    scope :started_or_completed, -> { where.not(job_status: 'unstarted') }

    def duration
      end_time - start_time if end_time
    end

    def in_progress!
      self.start_time = Time.zone.now
      super
    rescue
      Rails.logger.error "unexpected error updating log entry to :in_progress from #{caller}"
    end

    def succeeded!
      self.end_time = Time.zone.now
      super
    rescue
      Rails.logger.error "unexpected error updating log entry to :succeeded from #{caller}"
    end

    def failed!
      self.end_time = Time.zone.now
      super
    rescue
      Rails.logger.error "unexpected error updating log entry to :failed from #{caller}"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.4.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.3.3 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.3.2 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.3.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.3.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.2.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.2.0 app/models/spotlight/reindexing_log_entry.rb