Sha256: af3b7e559ae272dd398deaa7864cc07302b32792eb353f4160e75df6e261181e

Contents?: true

Size: 1.48 KB

Versions: 59

Compression:

Stored size: 1.48 KB

Contents

class HistoryTasksBuilder
  def distribution
    { 'running' => { recent: 3, total: 6 },
      'stopped' => { recent: 3, total: 7,
                     by_result: {
                       'success' => { recent: 2, total: 4 },
                       'warning' => { recent: 1, total: 2 },
                       'error' => { recent: 0, total: 1 },
                     } } }
  end

  # rubocop:disable Performance/TimesMap
  def build
    distribution.each do |(state, status_summary)|
      tasks = status_summary[:total].times.map do
        ForemanTasks::Task.create(type: ForemanTasks::Task.name,
                                  label: 'test',
                                  state: state,
                                  result: 'pending').tap do |task|
          task.update(state_updated_at: nil)
        end
      end
      recent_tasks = tasks.take(status_summary[:recent])
      recent_tasks.each { |t| t.update(state_updated_at: Time.now.utc) }

      untouched_recent_tasks = recent_tasks
      untouched_old_tasks = tasks - recent_tasks
      status_summary.fetch(:by_result, {}).each do |(result, result_summary)|
        result_summary[:recent].times do |_i|
          task = untouched_recent_tasks.shift
          task.update(result: result)
        end

        (result_summary[:total] - result_summary[:recent]).times do |_i|
          task = untouched_old_tasks.shift
          task.update(result: result)
        end
      end
    end
    # rubocop:enable Performance/TimesMap
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
foreman-tasks-8.1.2 test/support/history_tasks_builder.rb
foreman-tasks-8.1.1 test/support/history_tasks_builder.rb
foreman-tasks-8.1.0 test/support/history_tasks_builder.rb
foreman-tasks-8.0.2 test/support/history_tasks_builder.rb
foreman-tasks-8.0.1 test/support/history_tasks_builder.rb
foreman-tasks-8.0.0 test/support/history_tasks_builder.rb
foreman-tasks-7.2.1 test/support/history_tasks_builder.rb
foreman-tasks-7.1.1 test/support/history_tasks_builder.rb
foreman-tasks-7.2.0 test/support/history_tasks_builder.rb
foreman-tasks-7.1.0 test/support/history_tasks_builder.rb
foreman-tasks-6.0.3 test/support/history_tasks_builder.rb
foreman-tasks-7.0.0 test/support/history_tasks_builder.rb
foreman-tasks-6.0.2 test/support/history_tasks_builder.rb
foreman-tasks-4.1.6 test/support/history_tasks_builder.rb
foreman-tasks-5.2.3 test/support/history_tasks_builder.rb
foreman-tasks-6.0.1 test/support/history_tasks_builder.rb
foreman-tasks-5.2.2 test/support/history_tasks_builder.rb
foreman-tasks-6.0.0 test/support/history_tasks_builder.rb
foreman-tasks-5.2.1 test/support/history_tasks_builder.rb
foreman-tasks-5.3.0 test/support/history_tasks_builder.rb