Project

General

Profile

« Previous | Next » 

Revision d933e388

Added by Shimon Shtein almost 9 years ago

Fixes #10438 - Removed trends:clean task, as it is no longer needed

View differences:

lib/tasks/trends.rake
TrendImporter.update!
end
desc 'Clean Duplicates'
task :clean => :environment do
# This cleans out the duplicates created by multiple cron jobs.
# Note this can take a few minutes to run as the table is huge
# Get a hash of all TrendCounter pairs and how many records of each pair
# Keep only those pairs that have more than one record
dupes = TrendCounter.having('count(*) > 1').group([:trend_id, :created_at]).count
# Map objects by the attributes
object_groups = dupes.map do |attrs, count|
TrendCounter.where(:trend_id => attrs[0], :created_at => attrs[1])
end
# Take each group and destroy the extra records.
object_groups.each do |group|
group.each_with_index do |object, index|
object.destroy unless index == 0
end
end
end
desc 'Reduces amount of points for each trend group'
task :reduce => :environment do
start = Time.now
test/lib/tasks/trends_test.rb
Rake.application.rake_require 'tasks/trends'
Rake::Task.define_task(:environment)
Rake::Task['trends:reduce'].reenable
Rake::Task['trends:clean'].reenable
TrendCounter.unscoped.delete_all
Trend.unscoped.delete_all
......
assert_equal os_point_dates[5], new_intervals[2].interval_start
end
test 'trends:clean' do
trend = FactoryGirl.create(:foreman_trends, :operating_system)
created_at = Time.now
args = [:trend_counter, :trend => trend, :created_at => created_at, :updated_at => created_at, :count => 1]
# create a legit counter
FactoryGirl.create(*args)
# now create some dupes (skipping validations)
2.times do
FactoryGirl.build(*args).save(validate: false)
end
assert_equal 3, TrendCounter.where(trend_id: trend.id).length
Rake.application.invoke_task 'trends:clean'
assert_equal 1, TrendCounter.where(trend_id: trend.id).length
end
private
def create_trend_line(trend, values_line)

Also available in: Unified diff