Class: FadeOutTrendPowerWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/workers/fade_out_trend_power_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(multiplier = 0.9, batch_size = 1000) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/workers/fade_out_trend_power_worker.rb', line 4

def perform( multiplier = 0.9, batch_size = 1000 )
  Rails.application.eager_load! if Rails.env.development?

  ActiveRecord::Base.descendants.each do |klass|
    if klass.respond_to?( "has_trendable_concern?".to_sym )
      
      klass.items_to_fade_trending_power.select( :id ).find_in_batches( batch_size: batch_size ) do |batch|
        klass.where( id: batch.collect{ |i| i.id } ).update_all( "trending_power = trending_power * #{multiplier}")
      end
    else
      puts "#{klass.to_s} does not have trendable concern"
    end
  end
end