app/models/foreman_tasks/task/summarizer.rb in foreman-tasks-0.15.6 vs app/models/foreman_tasks/task/summarizer.rb in foreman-tasks-0.15.7

- old
+ new

@@ -45,20 +45,21 @@ @by_result[result].update(field, result_counts) end end end - def initialize(recent_timeframe = 24) + def initialize(scope = Task.authorized, recent_timeframe = 24) @recent_timeframe = recent_timeframe.hours + @scope = scope end def summarize_by_status aggregated_scope.where("result <> 'success'") end def latest_tasks_in_errors_warning(limit = 5) - ::ForemanTasks::Task.where('result in (?)', %w[error warning]).order('started_at DESC').limit(limit) + @scope.where('result in (?)', %w[error warning]).order('started_at DESC').limit(limit) end # Returns summary of tasks count, grouped by `state` and `result`, if form of: # # { 'running' => { recent: 3, total: 6 }, @@ -92,11 +93,11 @@ @summary[state].update(field, state_counts) end end def aggregated_scope - ::ForemanTasks::Task.select('count(state) AS count, state, result, max(started_at) AS started_at') - .group(:state, :result).order(:state) + @scope.select('count(state) AS count, state, result, max(started_at) AS started_at') + .group(:state, :result).order(:state) end def aggregated_recent_scope aggregated_scope.where("state_updated_at > ?", Time.now.utc - @recent_timeframe) end