Sha256: 3a6627d3a8cfb25f4ed2716d56a6c13f975ba7203462d429e8bdec6519ed107b

Contents?: true

Size: 615 Bytes

Versions: 1

Compression:

Stored size: 615 Bytes

Contents

module ForemanTasks
  class Task::Summarizer
    def initialize(scope = Task.authorized)
      @scope = scope
    end

    def summarize_by_status(since = nil)
      result = @scope.where("result <> 'success'")
                     .select('count(state) AS count, state, result, max(started_at) AS started_at')
                     .group(:state, :result).order(:state)
      result = result.where('started_at > ?', since) if since
      result
    end

    def latest_tasks_in_errors_warning(limit = 5)
      @scope.where('result in (?)', %w[error warning]).order('started_at DESC').limit(limit)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman-tasks-0.14.6 app/models/foreman_tasks/task/summarizer.rb