Sha256: 3f38e154e530708b47de5215d2071e02bc0f0e323ee1f3f1afc4f729a85e3340

Contents?: true

Size: 1006 Bytes

Versions: 63

Compression:

Stored size: 1006 Bytes

Contents

class InsightsClientReportStatus < HostStatus::Status
  REPORT_INTERVAL = 48.hours

  REPORTING             = 0
  NO_REPORT             = 1

  scope :stale, -> { where.not(reported_at: (Time.now - REPORT_INTERVAL)..Time.now) }
  scope :reporting, -> { where(status: REPORTING) }

  def self.status_name
    N_('Insights')
  end

  def to_label(_options = {})
    case status
      when REPORTING
        N_('Reporting')
      when NO_REPORT
        N_('Not reporting')
    end
  end

  def to_global(_options = {})
    case status
      when REPORTING
        ::HostStatus::Global::OK
      when NO_REPORT
        ::HostStatus::Global::ERROR
    end
  end

  def to_status
    in_interval? ? REPORTING : NO_REPORT
  end

  # prevent creation of the status on global refresh, but show it if the record already exists
  def relevant?(_options = {})
    persisted?
  end

  private

  def in_interval?
    return false unless reported_at
    (Time.now.utc - reported_at).to_i < REPORT_INTERVAL.to_i
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
foreman_rh_cloud-9.0.59 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.58 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.57 app/models/insights_client_report_status.rb
foreman_rh_cloud-10.0.1 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.56 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.55 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.54 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.53 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.52 app/models/insights_client_report_status.rb
foreman_rh_cloud-8.0.52 app/models/insights_client_report_status.rb
foreman_rh_cloud-9.0.51 app/models/insights_client_report_status.rb
foreman_rh_cloud-8.0.51 app/models/insights_client_report_status.rb
foreman_rh_cloud-7.0.48 app/models/insights_client_report_status.rb
foreman_rh_cloud-7.0.47 app/models/insights_client_report_status.rb
foreman_rh_cloud-8.0.50 app/models/insights_client_report_status.rb
foreman_rh_cloud-8.0.49 app/models/insights_client_report_status.rb
foreman_rh_cloud-8.0.48 app/models/insights_client_report_status.rb
foreman_rh_cloud-8.0.47 app/models/insights_client_report_status.rb
foreman_rh_cloud-8.0.46 app/models/insights_client_report_status.rb
foreman_rh_cloud-6.0.45 app/models/insights_client_report_status.rb