Sha256: 8ade91fbe3aa3491860c4a7956bff474b3fe46c84f2f4bf8a915733f7f1a59a6

Contents?: true

Size: 1.24 KB

Versions: 18

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

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

18 entries across 18 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.alpha.2 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-3.0.0.alpha.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.13.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.12.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.12.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.11.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.10.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.9.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.8.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.7.2 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.7.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.7.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.6.1.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.6.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.6.0 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.5.2 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.5.1 app/models/spotlight/reindexing_log_entry.rb
blacklight-spotlight-2.5.0 app/models/spotlight/reindexing_log_entry.rb