def summary
      @summary = Hash.new { |h, state| h[state] = Record.new }
      ENSURED_STATE_KEYS.each do |state|
        @summary[state] = state == 'stopped' ? RecordWithResult.new : Record.new
      end

      add_to_summary(aggregated_scope, :total)
      add_to_summary(aggregated_recent_scope, :recent)

      @summary.each.with_object({}) do |(key, record), hash|
        hash[key] = record.to_h
      end
    end
def summary
      @summary = Hash.new { |h, state| h[state] = Record.new }
      ENSURED_STATE_KEYS.each do |state|
        @summary[state] = state == 'stopped' ? RecordWithResult.new : Record.new
      end

      add_to_summary(aggregated_scope, :total)
      add_to_summary(aggregated_recent_scope, :recent)

      @summary.each.with_object({}) do |(key, record), hash|
        hash[key] = record.to_h
      end
    end
Returns summary of tasks count, grouped by `state` and `result`, if form of:

    { 'running'   => { recent: 3, total: 6 },
      'paused'    => { recent: 1, total: 3 },
      'stopped'   => { recent: 3, total: 7,
                       by_result: {
                         'success' => { recent: 2, total: 4 },
                         'warning' => { recent: 1, total: 2 },
                         'error'   => { recent: 0, total: 1 },
                       }}
      'scheduled' => { recent: 0, total: 3 }}