Sha256: 5c0b3aef97ad0857b1f000fb77472ff9d99f0918cd07295eff8c08dd0d6e56ff
Contents?: true
Size: 1.19 KB
Versions: 6
Compression:
Stored size: 1.19 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' # null start times sort to the top, to more easily surface pending reindexing default_scope { order('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
6 entries across 6 versions & 1 rubygems