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-5.0.46 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.45 app/models/insights_client_report_status.rb
foreman_rh_cloud-7.0.46 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.44 app/models/insights_client_report_status.rb
foreman_rh_cloud-7.0.45 app/models/insights_client_report_status.rb
foreman_rh_cloud-6.0.44 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.43 app/models/insights_client_report_status.rb
foreman_rh_cloud-4.0.36 app/models/insights_client_report_status.rb
foreman_rh_cloud-3.0.33 app/models/insights_client_report_status.rb
foreman_rh_cloud-6.0.42.2 app/models/insights_client_report_status.rb
foreman_rh_cloud-6.0.42.1 app/models/insights_client_report_status.rb
foreman_rh_cloud-6.0.43 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.42 app/models/insights_client_report_status.rb
foreman_rh_cloud-6.0.42 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.41 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.39 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.38 app/models/insights_client_report_status.rb
foreman_rh_cloud-4.0.35 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.37 app/models/insights_client_report_status.rb
foreman_rh_cloud-5.0.36 app/models/insights_client_report_status.rb