Sha256: 084e3efcf41923e9a374ba658332a31a2e3439cb0d34d1091e23baff0f766872

Contents?: true

Size: 990 Bytes

Versions: 6

Compression:

Stored size: 990 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

6 entries across 6 versions & 1 rubygems

Version Path
foreman_rh_cloud-10.0.3 app/models/insights_client_report_status.rb
foreman_rh_cloud-11.0.3 app/models/insights_client_report_status.rb
foreman_rh_cloud-11.0.2 app/models/insights_client_report_status.rb
foreman_rh_cloud-11.0.1 app/models/insights_client_report_status.rb
foreman_rh_cloud-11.0.0 app/models/insights_client_report_status.rb
foreman_rh_cloud-10.0.2 app/models/insights_client_report_status.rb